Basic requirements: Let the user enter the user name password Authentication successful display welcome information after the error three to exit the program upgrade requirements: can support multiple users login (prompt, through the list to save multiple account information) Users 3 times authentication failed, quit the program, restart the program when you try to log on, or lock the status (prompt: Need to save user-locked state to file)
Code:
#storing user names through lists, passwordsLogon_authentication =Falseuser_info= [['Li','123'], ['Yong','234'], ['Liyong','345']]logon_num= 3#Take a lock listLock_file = open ('Lock','R', encoding='Utf-8') Lock_list=Lock_file.read () lock_file.close ( )#Enter user password for the first timeuser_name = input ('Please input your name:') User_pass= Input ('Please input your password:')#cycle to determine user password forUser_iteminchUser_info:ifUser_name = =User_item[0]:#Determine if the list is locked ifUser_nameinchlock_list:Print('the user has been locked out! ') Break #Verify user password, re-enter password must be within the limit number of times forIinchRange (logon_num-1): ifUser_pass = = User_item[1]: Print('Landing Success') #flag Bits Verify login results and jump out of multi-layer loopsLogon_authentication =True Break Else: Logon_num= Logon_num-1Print('The password is wrong and you have', Logon_num,'the opportunity to enter the password again') User_pass= Input ('Please again input your password:') Else: Print('more than three times, the user is locked! ') Lock_file= Open ('Lock','a', encoding='Utf-8') Lock_list=lock_file.write (USER_NAME) lock_file.close () Break #Judging to jump out of a first-level loop iflogon_authentication: BreakElse: Print('no such user')#login successful, go to the next level pageiflogon_authentication:Print('Welcome to the space of {user}'. Format (User=user_name))
View Code
Python Practice (first week): Write a login certification program