Python Basic Login Interface

Source: Internet
Author: User

One:
Writing the Login interface
Basic requirements:

Let the user enter the user name password
Show welcome message after successful authentication
Exit the program after a three-time error

1.dic method
name_info={'Zhang':'123'}count=0 whileCount<3: Name=input ('Please enter user name:')    ifNameinchName_info:password=input ('Please enter your password:')        ifPassword = =Name_info[name]:Print('Welcome Log in')             Break        Else:            Print('password entered incorrectly, please re-enter the password:') Count+=1Else:        Print('input information is incorrect, please re-enter') Count+=1

2.list method

name_info=['Zhang','123']count=0 whileCount < 3: Name=input ('Please enter user name:')    ifName = =name_info[0]: password=input ('Please enter your password:')        ifPassword = = Name_info[1]:            Print('Welcome Log in')             Break        Else:            Print('Password input error, please re-enter') Count+=1Else:        Print('User name input error, please re-enter') Count+=1

Second: The requirements of the upgraded version:

    Can support multiple users login (prompt, through the list to save multiple account information)
After the user 3 authentication failed, quit the program, start the program again when attempting to log on, or lock the status (hint: the user locked state must be stored in the file)
name_info={'Zhang':{'passwd':'123','Count': 0},'Xin':{'passwd':'123','Count': 0},'Xiao':{'passwd':'123','Count': 0}} Count=0 whileTrue:name=input ('Please enter your user name:')    ifName not inchName_info:Print('This user name does not exist, please re-enter! ')        ContinueWith Open ('Db.txt','R') as F:lock_users=f.read (). Split ('|')        ifNameinchlock_users:Print('user%s has been locked'%name) Break    ifname_info[name]['Count'] > 2:        Print('too many attempts, locked') with open ('Db.txt','a') as F:f.write ('%s|'%name) Break    #if name in Name_info:Password=input ('Please enter your password:')    ifPassword = = name_info[name]['passwd']:        Print('Log In Success')         Break    Else:        Print('Password input error, please re-enter:') name_info[name]['Count']+=1

Python Basic Login Interface

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.