Implement a user login applet, if the password is wrong, you can retry three times, if three times are wrong, then locked
The database is in the following format, user name | password | locked, where lock field 0 is normal, 1 is locked
Root|admin123|0admin|admin123|1cevin|admin123|0
The code is as follows
Username = input ("Please input your username:") file_db= Open ('DB','R', encoding='Utf-8') file= Open ('DB','R', encoding='Utf-8') Test_list= [] forLineinchfile:f= Line.strip (). Split ('|') Test_list.append (f[0]) file.close ()ifUsernameinchtest_list: forLineinchfile_db:list_db= Line.strip (). Split ('|') ifList_db[0] = = Username andLIST_DB[2] = ='0': Password= Input ("Please input your password:") ifLIST_DB[1] = =Password:Print('Welcome%s login.'%(username)) Break Else: Print("Password is error") forIinchRange (4): ifi = = 3: Print("%s is already locked"%(username)) file_db= Open ('DB','R', encoding='Utf-8') file_new_db= Open ('new-db','W', encoding='Utf-8') forLineinchfile_db:ifUsernameinchline:test_list= Line.strip (). Split ('|') File_new_db.write (Test_list[0]+'|'+ test_list[1] +'|'+'1'+'\ n') Else: File_new_db.write (line) File_new_db.close () File_db.close () Break Else: Option= Input ("Do you want does to Tyr?") ifoption = ='No': Print("Byebye") Break Else: Password= Input ("Please input your password:") ifLIST_DB[1] = =Password:Print("yes,you have already login success!") Break Else: Print("Password is error") elifList_db[0] = = Username andLIST_DB[2] = ='1': Print("%s is already locked"%(username)) Break Else: PassElse: Print("%s is not register"% (username))
Python User Login Job