Requirements:
1. Enter the user name, password
2. Display welcome message after successful authentication
3. Input error 3 times after being locked
Flow chart:
The password_file format for creating the password file is as follows:
ADO 123
AAA 234
BBB 456
The lock file format is as follows:
Ado
Aaa
Bbb
The code is as follows:
Count_input = 0#error count, prompt for error 3 timesLock_list = []#Lock list, continuous error 3 prompt and add to user lock file forIinchRange (3): Count_input+ = 1Input_account= Input ("Input your account:") Input_password= Input ("Input your password:") lock_list.append (input_account)#add a user to a locked listF1 = open ("Password_file","R")#Read account password fileF2 = open ("Lock_file","R")#Read user lock file forLine2inchF2:ifInput_account.strip () = = Line2.strip ():#to determine whether the user output account is equal to the locked file line, which is the user lock state, prompts to exit, or continue Print("your account has been locked! quit ...") F2.close () Break Else: forLine1inchF1:ifinput_account+" "+input_passwordinchLINE1:#determine if the output account password is equal to the account password file, equal to print the welcome message and exit, or continue Print("Welcome back!") F1.close () Break Else: ifCount_input < 3:#when the error counter is less than 3 o'clock, prompt for re-entry, continue the next loop Print("wrong! Please input again!") Continue Else: ifLock_list.count (input_account) = = 3:#when the error counter equals 3 o'clock, the user is prompted to be locked out and Print("wrong Password!your account has been lock") F2= Open ("Lock_file","a")#Open User lock file in append formF2.write (input_account+"\ n")#to add a locked user to a locked filef2.close ()Else: Print("You have input wrong password 3 times,quit.")#three times input account not all the same time, print this line, and exit Break Break
(Python) Writing the login interface