Basic requirements:
- Let the user enter the user name password
- Show welcome message after successful authentication
- Exit the program after a three-time error
- Can support multiple users login (prompt, through the list to save multiple account information)
- User 3 authentication failed, quit the program, start the program again when trying to log in, or locked state, you need to save the user locked state to the file
1user_tab={2 'User01':{"Pass":"123","Count": 0},3 'User02':{"Pass":"123","Count": 0},4 'user03':{"Pass":"123","Count": 0},5 }6 whileTrue:7Username=input ("Please input your name:")8 if notUsernameinchUser_tab:9 Print("user does not exist, please check the user name, thank you! ")Ten Continue Onef = open ('User.txt','R') ABB =F.read (). Splitlines () - ifUsernameinchBB: - Print('The account has been locked! Please contact the Administrator!!! ') the Continue - -Password=input ("Please input your password:") - + ifuser_tab[username]['Count'] > 2: - Print('too many password errors entered! account is locked!!! ') +With open ('User.txt','A +') as F: A f.write (username) atF.write ('\ n') - Break - ifPassword = = user_tab[username]['Pass']: - Print('Welcome to the landing system', username) - Break - Else: in Print("bad password, please try again! ") -user_tab[username]['Count']+=1 to Continue
Python Multi-user authentication