1. 程式人生 > >模擬登錄

模擬登錄

== 錯誤 break pre spl close Coding put continue

#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






模擬登錄