users = {
'egon1': {'pwd': '1', 'erro_times': 0},
'egon2': {'pwd': '2', 'erro_times': 0},
'egon3': {'pwd': '3', '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("用户名不存在")