Requirements Description:
User login, password Three check, three failed, will lock the user name, do not allow Logon.
Solution:
1, clear the user name and password can be successfully logged in;
2, the user blacklist, three times the login failed, the user name is written to the blacklist;
3, detect the contents of the blacklist, if the same as the current login, it is not allowed to continue to enter the password, directly prompt the user is Locked.
Code implementation:
1 #-*-coding:utf-8-*-2 3 #Login three times lock user4 5 #for counting (three cycles of Judgment)6Count =07 8 #Real user name and password9Real_username ="iamxxx"TenReal_password ="123qwe" one a #read the contents of the blacklist -f = open ('Black_user','R') -Lock_file =F.read () the f.close () - -Username = Raw_input ("Please enter user name:") - + #determine if the user name entered is in the blacklist, if it is not allowed to continue entering the password - forIinchRange (1): + ifLock_file = =username: a Print("sorry, Your user name is locked and is not allowed for the time being! ") at Exit () - Else: - Continue - - #try to enter a password and count the number of inputs - forIinchRange (3): inPassword = raw_input ("Please enter your password:") - ifPassword = =real_password: to Print "Login successful! " + break - Else: the Print("Login Failed ...") *Count + = 1 $ Panax Notoginseng #If the wrong password is entered three times, the user name is locked and the user name is blacklisted - ifCount = = 3: the Print("sorry, you have entered the wrong number of passwords 3 times, will lock your account! ") +f = open ('Black_user','W') aF.write ('%s'%Username) theF.close ()
Execution Result:
Scenario 1: Enter the correct input user name: iamxxx Please enter the password: 123qwe login success! Scenario 2: input Error 3 times Please enter user name: iamxxx Please enter password:1 Login failed ... Please enter password:1 Login failed ... Please enter password:1 Login failed ... sorry, you have entered the wrong number of passwords 3 times, will lock your account! Execute again: Please enter your username: iamxxx sorry, your user name is locked and is not allowed for the time being!
"Python" User Login three times lock