Python 3-Time login Lock

Source: Internet
Author: User

2017-06-17

Requirements Description:

1. Enter your user name and password

2. Verify the password and username, and verify that the welcome message is displayed

3. Password error three times after locking the user

Ideas:

1.account.txt is the file that holds the user ID and password

2.lock.txt is the file that holds the locked user ID, which is empty by default

3. Determine if the user is in the blacklist lock.txt

4. Determine if the user password is correct, after three failures, add the user ID to the blacklist

Code implementation:

1 #-*-coding:utf-8-*-2Count = 0#counter to record the number of times a user has entered a password3lock = []#define an empty list4User_pass = []5Flag = 16Username = Raw_input ("Please enter your name:")7f = open ("Lock.txt","r+")#read the contents of the blacklist8Lock_list =F.readlines ()9 f.close ()Ten  forLock_lineinchLock_list:#traversing the blacklist file contents into the lock list Oneline = Lock_line.strip ('\ n') A Lock.append (line) -     ifUsernameinchLock#determine if the user name entered is in the blacklist -         Print("your%s user is already in the blacklist"%(username)) theExit ()#Exit Program -     Else: -          whileCount < 3: -Count = Count + 1 +passwd = Raw_input ("Please enter your password:") -f = open ('Account.txt','R') +User_file = F.readlines ()#read the user name and password in the Account.txt A f.close () at              forIinchUser_file: -User_pass =I.strip (). Split () -                 ifUsername = = User_pass[0] andpasswd = = User_pass[1]:#The account password is correct, prompt login is successful, exit loop -                     Print("Login Successful ...") -Flag =True - exit () in                 Else: -                     Continue to             ifFlag isTrue: +                  Break -             Else: the                 ifCount = = 3:#The user is appended to the blacklist if the password is incorrectly 3 times *                     Print("your account has been locked ...") $f = open ("Lock.txt","a")Panax NotoginsengF.write ('%s\n'%username) - f.close () the                      Break

Pending optimization:

1. Does not determine the user does not exist in the Account.txt file the situation

2. Three failed to append to the blacklist of the user, the password is still able to log in correctly

Python 3-Time login Lock

Related Article

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.