"Python" User Login three times lock

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.