用户登陆程序(python3.x)
程序员文章站
2022-06-28 18:00:24
程序要求: 1.输入用户,如果没有注册,先注册 2.认证成功先是欢迎信息 3.输错三次后锁定 ......
程序要求:
1.输入用户,如果没有注册,先注册
2.认证成功先是欢迎信息
3.输错三次后锁定
1 username = input("username:") 2 #判断用户被锁了 3 with open("lock.txt",'r+') as l: 4 lockname=l.readlines() 5 if username in lockname: 6 print ("you user is locked,you can not login,plese you go to unlock...") 7 exit() 8 else: 9 print ("you user unlock,plese next...") 10 11 #判断用户是否注册,如果注册进行登陆,没有注册则进行注册 12 for i in range(2): 13 with open("register.txt",'r+') as f: 14 regname=f.readlines() 15 if username in regname: 16 print("your user have registed........plese logining...") 17 break 18 else: 19 print("this system have not your user,you must to regist....") 20 with open("passwd.txt",'r+') as p: 21 reguser = input("reguser:") 22 regpasswd= input("regpasswd:") 23 f.writelines('\n') 24 f.writelines(reguser) 25 p.writelines('\n') 26 p.writelines(regpasswd) 27 28 #进行登陆 29 loginname=input("loginname:") ##这个name与注册的是相同的 30 for i in range(3): 31 loginpasswd=input("loginpasswd:") 32 with open("passwd.txt",'r+') as w: 33 passwd=w.readlines() 34 35 if loginpasswd in passwd: 36 print ("welcome to here....") 37 break 38 elif i<2: 39 print ("your passwd is false...plese try agin...") 40 else: 41 print ("you have tried three times,your user have locked") 42 #向锁文件添加用户 43 with open("lock.txt",'a+') as k: 44 k.writelines('\n') 45 k.writelines(loginname)