Requirements
1. Enter the user name and password
2. Verify successful Display Welcome page
3. Enter the error 3 times, lock the user name
Also saw a lot of great God, teacher, Brother's code inspired, just write the following rewrite version
This code is also blind a few to work out, the specific principle is not very understand
Name = Dict (K.strip (). Split (' = ') for k in Name_list.readlines ())
If the position of strip () and split (' = ') is exchanged, then the cause of the error is estimated to be strip () can only operate on STR type
Known Bugs:
1. Enter 2 times the same correct username and wrong password, enter another correct user name and password for the 3rd time, then lock the user name entered for 3rd time
User name and password file Name_list.ini content as follows:
Mask=123
Jake=123qq
Qb11=123qwe
Lock user list file Lock_list.ini content defaults to null:
i =0g= 3W=0j=0Print(" "************************************* Welcome to the log in system *************************************" ") whileI < 4: I= i + 1I_name= Input ('Please enter your user name:')#Enter user namename_list = open ('Name_list.ini','R')#read the user name and password dictionaryName = Dict (K.strip (). Split ('=') forKinchname_list.readlines ()) name_list.close () lock_list= Open ('Lock_list.ini','R')#Read locked user namelock = [K.strip () forKinchlock_list.readlines ()] Lock_list.close () LK= I_nameinchLock#Enter a user name comparison lock listf = i_nameinchName#user name entered compare to registered user name ifLen (i_name) = = 0orj = = 3:#Check if the user name you entered is empty Print('the user name you entered is empty') J= j + 1ifj = = 3: Print('you have entered 3 consecutive empty user names, the system forced to quit') I= 4elifLK = =True:Print('your user name has been locked, please contact the Administrator') I= i + 4eliff = =false:w= w + 1Print('the user name you entered is invalid, please re-enter') ifW = = 3: Print('you have entered an invalid user name of 3 times, the system forced to quit,') I= 4eliff = = True:#If the user name is correct, take its password and let the user enter the passwordMima =Name[i_name] I_mima= Input ('Please enter your password:') ifI_mima = =Mima:Print('Welcome,%s'%i_name)#The password displays the Welcome page correctlyi = 4Else: G= G-1Print('User name or password error \ n (you also have%s chance)'%g)ifG = =0:Print('you have entered the wrong password 3 times and have been locked by the system') A= Open ('Lock_list.ini','a')#password Error 3 times, write user name to locked listA.write (str (i_name +'\ n') ) A.close () I= 4
Can we streamline the code?
Can we enhance the function?
Learning Python Login interface rewrite version