Python-based login interface and python-based interface
1. Enter the user name and password;
2. After successful authentication, the welcome information is displayed;
3. After three errors, the account is locked.
Account file: user.txt
Lock file: locked.txt
The flowchart is as follows:
#-*-Coding: UTF-8-*-# Author Caoxlimport sysaccount_file = 'e: \ user.txt 'locked _ file = 'e: \ locked.txt 'def deny_account (username ): print ('your user has been locked ') with file (locked_file, 'A') as deny_f: deny_f.write (' \ n' + username) def main (): retry_count = 0 retry_limit = 3 # loop times while retry_count <retry_limit: # the user can log on three times at most. username = raw_input ('enter your username :') # instruct the user to enter the user name with file (locked_file, 'R') as lock_f: # Use the with method to open locked_f Ile value lock_f to prevent forgetting f. close () close the file for line in lock_f.readlines (): # cyclically traverse the content of each row if len (line) = 0: # process each line of content. continue if username = line. strip (): # exploitation. strip removes the linefeed to match the username. Sys. exit ('the user is locked! ') If len (username) = 0: # the user name cannot be blank when prompted to log on! Print ('user name cannot be blank; enter 'Again) continue password = raw_input ('enter your password:') # instruct the user to enter the password with file (account_file, 'R') as account_f: flag = False for line in account_f.readlines (): user, pawd = line. strip (). split () # process the user name and password. if username = user and password = pawd: # determine the user name and password print ('success! ') Flag = True break # exit for loop if flag = False: # Do not prompt users to re-enter after three inputs. If retry_count <2: print ('the user name or password you entered is incorrect. Please enter it again! ') Retry_count + = 1 else: print (' Welcome to the successful login !! ') Break # The flag is used to successfully launch the entire cycle! Deny_account (username) # Add the locked account to the document using the def function above. if _ name _ = '_ main _': main ()
View Code