Python 账户密码登陆验证。
账户和密码存放在文件中,从文件中读取并比较
密码密文
验证三次后,如不成功则锁定账户
1 import os 2 import getpass 3 4 5 times = 0 6 while times < 3: 7 UserName = input("请输入用户名:") 8 PassWord = getpass.getpass("请输入密码:") 9 10 11 with open("config/userlist.txt", 'r') as f : 12 for userlist in f : 13 if userlist.find(UserName) != -1 : 14 #print(type(userlist.find(UserName))) 15 _UserName,_PassWord = userlist.strip().split(',') 16 break 17 else : 18 _UserName = 'aa' 19 continue 20 21 if _UserName == 'aa' : 22 print("用户" + UserName + "不存在") 23 continue 24 25 if UserName == _UserName and PassWord != _PassWord : 26 print("密码不对") 27 elif UserName == _UserName and PassWord == _PassWord : 28 print("欢迎回来") 29 break 30 else : 31 print("再检查一次吧") 32 times += 1 33 else : 34 print("用户已锁定,请稍后重试!") 35 with open("config/lockuser.txt",'a+') as l: 36 l.write(UserName + '\n')