oldboy-作业01.登录多次进行账号锁定

时间:2023-03-09 08:10:41
oldboy-作业01.登录多次进行账号锁定
"""
可以支持多个用户登录 (提示,通过列表存多个账户信息)
用户3次认证失败后,退出程序,再次启动程序尝试登录时,还是锁定状态(提示:需把用户锁定的状态存到文件里) ""

users = {

    'egon1': {'pwd': '', 'erro_times': 0},
'egon2': {'pwd': '', 'erro_times': 0},
'egon3': {'pwd': '', 'erro_times': 0}, } while True: name = input('请输入用户名:')
pwd = input('请输入密码:') if name in users: with open('usr_lock', 'r') as f:
lock = f.read().rstrip(",").split(",") if name in lock:
print("该用户已被锁定")
break elif pwd == users[name]["pwd"]:
print("登录成功") else: print("密码输入错误")
users[name]['erro_times'] += 1 if users[name]['erro_times'] == 3:
print("用户被锁定")
with open('usr_lock', 'a') as f:
f.write("%s," % name)
break else:
print("用户名不存在")