Python learning --------- login system code implementation, python ---------

Source: Internet
Author: User

Python learning --------- login system code implementation, python ---------

Question requirements:

I. login Portal

1. Enter the user name and password
2. The welcome information is displayed after the authentication is successful.
3. Lock after three wrong attempts

Readme:

In the hosts file, the account: Password is stored in one row.) If the output is correct, welcome to the system. If the error occurs three times, the user is locked.

2. users who can find the second, third, and multiple users in a loop have not been found before,

3.txt files are created, and information is stored as above. Run the command.

Mind Map:

 

The Code is as follows:

1 #-*-Coding: UTF-8-*-2 # Author: Eric. shen 3 #2018.02.06 4 #1. logon portal 5 #1. enter username and password 6 #2. after successful authentication, the welcome information is displayed 7 #3. lock 8 9 print ("10 *************************** * ************************************ 11 *** * 12 *** 13 *** Welcome into the landing system *** 14 *** 15 ***: eric. shen *** 16 ************************************ * ************************** 17 """) 18 19 # determine whether the user is locked 20 def judge_lock_user (): 21 Username = input ("Enter your username:") 22 f = open ("user_lock.txt", "r +") 23 for line_list in f. readlines (): 24 if username = line_list: 25 exit ("your account has been locked! ") 26 f. close () 27 return username # return the username text you just entered for the following 28 29 def judge_password (username ): 30 num = 031 while num <3:32 password = input ("enter your password:") 33 f_user = open ("user_info.txt", "r ") 34 for line in f_user.readlines (): 35 line = line. strip () # remove the last line break 36 index, item = line. split (":") # assign a value to 37 if index = username and item = password: 38 f_user.close () using a colon () 39 exit ("Welcome % s to system" % (username) 40 if num <:41 num + = 142 if num <= 2: # No chance to output the following statement 43 print ("Incorrect password, please enter again. You still have % s chance to enter" % (3-num )) 44 elif num = 3: # Write user_lock45 f_lock = open ("user_lock.txt", "") 46 f_lock.write ("\ n" + str ("% s" % (username) 47 f_lock.close () 48 exit ("your account has been locked") 49 else: 50 print ("program exit") 51 52 53 54 55 56 57 if _ name _ = "_ main __": 58 # determine whether the user is locked 59 name = judge_lock_user () 60 61 judge_password (username = name) 62 # No, then determine whether the password is correct
View Code

 

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.