# 可以支持多个用户登录 (提示,通过列表存多个账户信息)
# 用户3次认证失败后,退出程序,再次启动程序尝试登录时,还是锁定状态(提示:需把用户锁定的状态存到文件里)
dic={
'raimond':{'password':'123','count':0},
'jack':{'password':'456','count':0},
'lily':{'password':'789','count':0},
}
count=0
while True:
name=input('u>>: ')
if name not in dic:
print('用户不存在')
continue
with open('users_list.txt','r') as f:
lock_users=f.read().split('|')
if name in lock_users:
print('用户%s已经被锁定' %name)
break
if dic[name]['count'] > 2:
print('次账号已经被锁定')
with open('db.txt','a') as f:
f.write('%s|' %name)
break
password=input('p>>: ')
if password == dic[name]['password']:
print('登录成功')
break
else:
print('用户名或密码错误')
dic[name]['count']+=1
C:\Users\user\AppData\Local\Programs\Python\Python36\python.exe “C:/Users/user/PycharmProjects/hellow python/test.py”
u>>: raimond
p>>: 1
用户名或密码错误
u>>: raimond
p>>: 2
用户名或密码错误
u>>: raimond
p>>: 3
用户名或密码错误
u>>: raimond
次账号已经被锁定
或者
Process finished with exit code 0
C:\Users\user\AppData\Local\Programs\Python\Python36\python.exe “C:/Users/user/PycharmProjects/hellow python/test.py”
u>>: raimond
p>>: 123
登录成功
Process finished with exit code 0