Python login, enter password three times

Source: Internet
Author: User

The first Python code, wrote a day, finally did not error, it is worth remembering.

Basic requirements:

Write a login interface, login three times to lock the user

1. Contains a user information file, user name and password

2. Blacklist file

Process:

1. First check whether the blacklist, if present, do not let the login

2. If not in the blacklist is not in the user list, you are prompted to find the administrator to open

3. If the user table is prompted for a password, if more than three times to enter the password, the user is blacklisted.

Code implementation Flowchart:

#-*-coding:utf-8-*-#author:rxs002 2016-8-1 White= Open ('Whitelist.txt','R') Black= Open ('Blacklist.txt','R') passwd= Open ('Pwdlist.txt','R') NameList=White.read () blacklist=black.read () pwdlist=passwd.read () Namecount=0pwdcount=0totalcount=0#program Start whileTrue:username= Input ('Please enter user name:'). Strip ()#print (namelist)#print (username)    ifUsernameinchblacklist:Print('users in the blacklist, please contact the administrator! -----')        Print('program because the Blacklist normal end!!! ')         Break    elifUsernameinchnamelist:pwd= str (Input ('Please enter user password:') . Strip ()ifPwdinchNameList:Print('password is correct, welcome to login! ')            Print('The program because the password entered correctly, the normal end!!! ')             Break        elifPwd not inchNameList: forPwdcountinchRange (0, 3):                ifPwdinchNameList:Print('password input is correct, please enter the system!!! ')                     Break                Else: pwd= str (Input ('password is incorrect, please re-enter the password:') . Strip () Pwdcount+ = 1Print('You also have%d chances to enter your password'% (3-Int (pwdcount)))  whilePwdcount >= 3:                Print('password input more than three times, the account is locked, please contact the administrator to deal with! ') black.close () Black1= Open ('Blacklist.txt','a') Black1.write (username) black1.write ('\ n') Black1.close () Break         Break    Else:        Print('user does not exist, please contact administrator to create user!!! ')         Breakwhite.close () black.close () Passwd.close ( )
View Code

Python login, enter password three times

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.