1. Requirements
* Default user name and password, enter user name and password.
* Authentication failed, return failure information, successful authentication, return success information.
* If the user entered three password error, then lock the machine
2, involving knowledge points
* File operations, create a file, write files, read files, append files
* Loop, set the number of user allowed errors, use while loop
* Judge, determine whether the user is locked user if...else ...
3. Analysis
* Use file operations to create a file as a database file. Role 1 Determines whether the user ID in this file, role 2 will fail the user to write the library of the file.
* Set the loop, jump out of the loop correctly, and continue the loop incorrectly.
4. Flowchart
5. Code
1Default_accound ="Xiefangyuan" #set default account and password2Default_password ="19910329" #set default account and password3user ="192.9.169.49" #set the user ID to lock the user and subsequently add functions such as acquiring Machine Mac4sql = open ("Sql.log","a")#a database file is recommended for storing user identities5Sql.write ("database files, mistakenly deleted! \ n")#Write6Sql_r = open ("Sql.log","R")#Read database file contents7 ifUserinchSql_r.read ():#determine if the user is locked out8 Print("the user is locked out of the user and cannot be used! ")9 Else:Tenn = 3#set the number of cycles One whilen >0: An = n-1 -account = str (input ("User name:"))#user Input account password -Password = str (input ("Password:"))#user Input account password the ifaccount = = Default_accound andPassword = =Default_password: - Print("enter right, entering! ") - Break - Else: + Print("input Error, please re-enter! You have a chance to do it again.". Format (n)) - Else: +sql = open ("Sql.log","a") ASql.write (user)#Write User ID at Print("the number of errors has reached three times, the user is locked! ")
Python combat-write basic landing portals