说明:
1、用户原文件存储在文件中_userinfo
2、判断是否存在登陆错误的用户_被锁定的用户_wrong_name2,没有创建,并写入用户文件头username,带逗号,锁定用户以‘逗号‘隔开;
3、判断输入用户是否存在锁定账户中(取出用户名,存入列表,)
4、逻辑控制,用户名,或秘密超过3次记录该用户的用户名到文件;
import osif os.path.exists(‘wrong_name2‘): file_wrong=open(‘wrong_name2‘) f=file_wrong.readline() lock_name=f.split(‘,‘) for i in lock_name: print(i) file_wrong.close()else: with open(‘wrong_name2‘,‘w‘) as f_wrong: f_wrong.write(‘username‘) f_wrong.write(‘,‘) lock_name=f_wrong.split(‘,‘) for i in lock_name: print(i) file_wrong.close() file=open(‘userinfo2‘)info=eval(file.readline())print(info)l_name=[]l_passwd=[]l_count=[]count=0for i in info: l_name.append(i[0])for k in info: l_passwd.append(i[1]) while True and count<3: name=input(‘pls input your name:‘).strip() if name in lock_name: print(‘the count is locked...exit.‘) exit() while name in l_name and count<3: count=0 while count<3: passwd=input(‘pls input your passwd:‘).strip() if passwd in l_passwd: print(‘welcome‘) break else: count+=1 print(‘wrong passwd‘) print(count) else: l_count.append(name) print(l_count) f_w=open(‘wrong_name2‘,‘a+‘) f_w.write(str(l_count[-1])) f_w.write(‘,‘) f_w.close() print(‘count>>>%s was locked...‘%name) exit() else: count+=1 print(‘wrong name...‘) continueelse: l_count.append(name) f_w=open(‘wrong_name2‘,‘a+‘) f_w.write(str(l_count[-1])) f_w.write(‘,‘) print(‘count>>>%s was locked...‘%name)
时间: 2024-09-30 14:17:54