Python Practice (first week): Write a login certification program

Source: Internet
Author: User

Basic requirements: Let the user enter the user name password Authentication successful display welcome information after the error three to exit the program upgrade requirements: can support multiple users login (prompt, through the list to save multiple account information) Users 3 times authentication failed, quit the program, restart the program when you try to log on, or lock the status (prompt: Need to save user-locked state to file)

Code:
#storing user names through lists, passwordsLogon_authentication =Falseuser_info= [['Li','123'], ['Yong','234'], ['Liyong','345']]logon_num= 3#Take a lock listLock_file = open ('Lock','R', encoding='Utf-8') Lock_list=Lock_file.read () lock_file.close ( )#Enter user password for the first timeuser_name = input ('Please input your name:') User_pass= Input ('Please input your password:')#cycle to determine user password forUser_iteminchUser_info:ifUser_name = =User_item[0]:#Determine if the list is locked        ifUser_nameinchlock_list:Print('the user has been locked out! ')             Break        #Verify user password, re-enter password must be within the limit number of times         forIinchRange (logon_num-1):            ifUser_pass = = User_item[1]:                Print('Landing Success')                #flag Bits Verify login results and jump out of multi-layer loopsLogon_authentication =True Break            Else: Logon_num= Logon_num-1Print('The password is wrong and you have', Logon_num,'the opportunity to enter the password again') User_pass= Input ('Please again input your password:')        Else:            Print('more than three times, the user is locked! ') Lock_file= Open ('Lock','a', encoding='Utf-8') Lock_list=lock_file.write (USER_NAME) lock_file.close () Break    #Judging to jump out of a first-level loop    iflogon_authentication: BreakElse:    Print('no such user')#login successful, go to the next level pageiflogon_authentication:Print('Welcome to the space of {user}'. Format (User=user_name))
View Code

Python Practice (first week): Write a login certification program

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.