Python 登录系统
----------------------------------------------------------------------------------------
该程序主要实现了以下3点功能:
1.用户登录验证
2登陆成功出现欢迎信息
3连续登录三次,密码错误冻结账号
----------------------------------------------------------------------------------------
uesr_db 为用户账号密码等信息:
{"username":"asd","password":"1234","erro":1} {"username":"fffdsaf","password":"1234ff","erro":1} {"username":"asdf","password":"1234ff","erro":1} {"username":"sdaf","password":"1234565","erro":1}
f2 为已冻结账号:
{'password': '1234', 'erro': 1, 'username': 'asd'}
登录系统代码:
import sys def log_in(): username = input("please input you username:").strip() password = input("please input your password:").strip() return username,password f = open("user_db","r+") userinfo = f.readlines() cout = 0 username,password = log_in() def main(username,password): cout = 0 for i in userinfo: i = eval(i.strip()) with open("f2", "r") as f2: frozen_user = f2.readlines() for x in frozen_user: x = eval(x.strip()) if username == x["username"] : print("您的账号已冻结") sys.exit(0) if username == i["username"]: while(1): if username == i["username"]: if password == i["password"]: print("您已成功登陆") sys.exit(0) else: cout +=1 if cout <4 : print("密码错误!") username, password = log_in() else: print("您的账号已冻结") a = str(i) with open("f2","w") as f2: f2.write(a) break else: main(username, password) break else: cout +=1 if cout < len(userinfo): continue else: print("您的账号不存在") username, password = log_in() main(username, password) main(username,password)