Python input error password user lock implementation method, python Error

Source: Internet
Author: User

Python input error password user lock implementation method, python Error

The Editor brings you the implementation method and specific process of user locking after multiple password input errors are implemented using python, so that you can better understand the running process.

1. create a new file to store the whitelist users (in the correct format of registered users: username: password), and create a file to store the blacklisted users (users with incorrect usernames entered three times ).

2. Read the whitelist file, assign the content to a variable, and disable it.

3. the variables are separated by ":", and the first (index is 0) is assigned to username, and the second (index is 1) is assigned to password.

4. Read the blacklist file, assign the content to a variable, and disable it.

5. Define a variable (t) to store user input times,

6. Perform a loop. When the number of cycles is less than three times, continue the loop. When the number is greater than three times, the system will prompt you to enter more than three times and the account will be locked,

During recycling, enter the user name and determine whether the user name is in the blacklist. If the user name is in the blacklist, the system prompts "this account has been locked". If the user name is not in the blacklist, the system continues to judge the user name in the whitelist, if the user name is on the list again, continue to judge whether the password is correct.

#! /Usr/bin/env python #-*-coding: UTF-8-*-# @ lynn # Read login. user File, assign the content to the variable login_f1, and disable f1 = open ('login. user', 'R') login_f1 = f1.read () f1.close () # extract the value of the variable login_f1 with the separator ':' # 0th-bit elements, assigned to another variable ruserruser = login_f1.strip (). split (":") [0] # extract the 1st-bit element and assign the value to another variable rpwdrpwd = login_f1.split (":") [1] # Read the lock of the blacklist file. user, assign the content to the variable lock_f2, and disable f2 = open ('lock. user', 'R') lock_f2 = f2.readlines () f2.close () # defines a variable for counting t = 0 # When When t is less than 3, there is an infinite loop. While t <3: name = input ("enter account:") for a in lock_f2: if name = a: print ("Sorry! This account has been locked. ") Exit () for B in login_f1: if name = ruser: t = 0 while t <3: pwd = input (" enter the password :") if pwd = rpwd: print ("Welcome! % S "% name) exit () else: print (" Sorry! Wrong password. ") t + = 1 else: print (" sorry, the error count reaches 3, and the account is locked! ") F = open ('lock. user', 'w') f. write ('% s' % name) f. close () exit ()

Related Example 2 (python 3.0 ):

 

#-*-Coding: UTF-8-*-# simulate user logon as required, logon count = 0 # realname passwdReal_Username = "test" Real_Password = "test" # Read blacklisted content f = open ('black _ user ', 'R') lock_file = f. read () f. close () Username = input ('enter User name: ') # judge whether the input user is in the blacklist. If so, the password for I in range (1) is not allowed ): if lock_file = Username: print ('Sorry, your user is locked and is not allowed for use now! ') Exit () else: continue # try to enter the Password and count the number of inputs for I in range (3): Password = input ("enter the Password :") if Username = Real_Username and Password = Real_Password: print ("Logon successful") break else: print ("Logon Failed") count + = 1 # if three wrong passwords are entered, the user name is locked, and the user name is blacklisted. if count = 3: print ("sorry, the number of wrong password attempts you have entered has reached 3, and your user name will be locked ") f = open ("black_user", "w") f. write ("% s" % Username) f. close ()

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.