Requirements: Let the user enter the user name password Authentication successful display welcome information after the error three after the exit program can support multiple users logged in the user 3 times authentication failed, quit the program, restart the program when you try to log on, or lock the state
#-*-coding:utf-8-*-#Author:skyellFlag=trueaccount_list= {'Xiaopang':'123','Haohao':'234'}#account PasswordUsername = input ('Please input your username:') Lock_name= Open ('Lockname_list.txt','R') forIinchLock_name:lockname=I.strip ()ifLockname = =Username:Print('your account has been locked!') Break Else: Continuelock_name.close ()ifUsername! =Lock_name:password_wrong=0 whileFlag:password= Input ('Please input your password:') Acc_name= [keys forKeysinchAccount_list]#use list generation to deposit account information into the list ifUsernameinchAcc_name:ifAccount_list[username] = = Password:#determine if the account and password are correct Print('Welcome back!') Flag=False Break Else: Print('Please try again!') Password_wrong+=1ifPassword_wrong==3:#password Error 3 times, lock user Print('your account has been locked') Lock_name= Open ('Lockname_list.txt','A +') Lock_name.write ('\ n') Lock_name.write (username)#write the locked account to the locked filelock_name.close ()Else: Print('Account was not found') Flag=False Break
Basic implementation requirements, continue to continue!
Python User Login Program