#coding:utf-8
"""
1. 用户输入帐号密码进行登陆
2. 用户信息保存在文件内
3. 用户密码输入错误三次后锁定用户
"""
dic={
'egon1':{'password':'123','count':0},
'egon2':{'password':'123','count':0},
'egon3':{'password':'123','count':0},
}
flag=True
while flag:
name=input('type your name:').strip()
with open('a.txt','r',encoding='utf-8') as red_user:
if name in red_user.read().split('|'):
print("账户已锁定")
continue
if name not in dic:
print('name is not in dic')
continue
else:
while flag:
passwd=input('type your passwd:')
if passwd!=dic[name]['password'] and dic[name]['count']<=2:
print('passwd is wrong')
dic[name]['count']+=1
continue
elif dic[name]['count']>2:
print("chao guo 3 ci")
user=open('a.txt','a',encoding='utf-8')
user.write(name+'|')
user.close()
break
if passwd==dic[name]['password']:
print("login success")
flag=False