Python3.0 simulates user logon. The instance is locked three times by mistake, and the python3.0 User Logon

Source: Internet
Author: User

Python3.0 simulates user logon. The instance is locked three times by mistake, and the python3.0 User Logon

Python3.0 simulates user logon, And the instance is locked three times by mistake

The instance is as follows:

#-*-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 ()

Python basics-implement logon with user passwords and Lock three times after an error occurs

Job Requirements:

1. Enter the user name and password

2. The welcome information is displayed after the authentication is successful.

3. Lock after three wrong attempts

Implementation ideas:

1. Check whether the user is on the blacklist. If the user is on the blacklist, the account is locked.

2. Determine whether the user exists. If the user does not exist, the system prompts that the account does not exist.

3. Check whether the account and password are correct. If you do not have the chance to enter the password three times. The account is locked due to three wrong attempts.

#! /Usr/bin/env python # _ * _ conding: UTF-8 _ * _ count = 0 # counter username = "aaa" # logon username userpassword = "asd" # logon password # Read the blacklist user f = open ("aaa.txt ", "r") file_list = f. readlines () f. close () lock = [] name = input ("Login Username:") # determine whether the user is blacklisted for I in file_list: line = I. strip ("\ n") lock. append (line) if name in lock: print ("your account is locked. Contact the administrator. ") Else: # if the user is not in the blacklist, determine whether the user exists. If name = username: # if the password is incorrect three times in a row, the account is locked. While count <3: password = input ("Logon password:") if name = username and password = userpassword: print ("Welcome, % s" % name) break else: print ("account and password do not match") count + = 1 else: print ("sorry, your account has been locked three times consecutively due to an error. Please contact the administrator. ") F = open (" aaa.txt "," w + ") li = ['% s' % username] f. writelines (li) f. close () else: print ("the user name does not exist. Enter the correct user name. ")

The above python3.0 simulated user login, three error locks of the instance is all the content shared by xiaobian to everyone, I hope to give you a reference, but also hope you can support a lot of help homes.

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.