import json ###检查输入的用户是否被锁 def UserLogin(): UserFile = open("UserFile.text", "rb") UserInput = input("请输入账号:") UserRead = json.load(UserFile) for UserRead_ in UserRead: if UserRead_["UserID"] == UserInput: print("[%s]该用户亦被锁,请联系管理员!"%UserInput) exit() else: UserPass(UserInput) UserFile.close() lock_List = [] ###用户锁定读取文件 def Userlock(lock,UserInput): for lock_list in lock: lock_List.append(lock_list) UserLock(lock_List,UserInput) ###用户锁定修改 def UserLock(lock_List,UserInput): lock_List.append({"UserID":UserInput}) UserLock__ = open("UserFile.text","w") UserLock_ = json.dump(lock_List,UserLock__) print("您的[%s]账户被冻结,请联系管理员!!!"% UserInput) UserLock__.close() ###检查用户输入的账号是否存在,如果存在就输入密码,如果不存在就提示用户 def UserPass(UserInput): UserPassRead = open("UserReadFile.text","rb") User_PassRead = json.load(UserPassRead) count_1 = 0 for Userread_ in User_PassRead: count_1 += 1 if Userread_["UserID"] == UserInput : count_ = 0 while count_ < 3: count_ += 1 User_Pass = input("请输入密码:") if Userread_["UserPass"] == User_Pass: print("[%s]欢迎您"%UserInput) exit() elif count_ < 3: print("密码错误,请重新输入!!您还剩[%s]" % (3 - count_)) elif count_ == 3: k = open("UserFile.text","rb") lock=json.load(k) Userlock(lock,UserInput) k.close() exit() elif len(Userread_) == count_1: print("[%s]该账号还未注册"%UserInput) print("您可以前往注册(a)/重新输入账号(b)") Input_ = input("a/b:") if Input_ == "a": exit() else: UserLogin() UserPassRead.close() UserLogin()
[{"UserID": "123"}, {"UserID": "122"}, {"UserID": "121"}, {"UserID": "120"}, {"UserID": "124"}, {"UserID": "1341"}]
[{"UserID": "1341", "UserPass": "13421731041"},{"UserID": "13421731047", "UserPass": "13421731041"}]