Python-based login interface and python-based interface
Job: Write the login interface
- Enter user name and password
- Welcome information displayed after successful authentication
- Lock after three wrong attempts
Use = [] # define an empty list to blacklist the file user. in the log user name writing list, dic = {'gaoqiang ': '000000', 'shanghai': '000000', 'laowan': '000000', 'laogao ': '20140901', 'laofeng ': '000000' }## account information is stored in a dictionary. Here, you can query and write the dictionary from the txt file. luck_num = 0 # The initial value is pulled three times by entering the password count once. blacklist function dic_list = list (dic. keys () # display the list in the form of a list. while True: user = input ("Enter the user name:") f = open ('user. log', 'R') for line in f. readlines (): # from user. log reads the username line = line in the blacklist. strip () use. append (Line) # Add the result to the empty use list. close () # print (use) if user in dic_list and user not in use: # Start to judge whether the input user name is in dict_list and whether it is in the blacklist while True: password = input ('Enter the password :') # if both of the above conditions are met, you need to add ''to the dictionary password to start to lose the password. Otherwise, the int type and string type cannot be compared or you can add int () while not password to the input. strip (): # If you enter null, the system prompts you to continue entering password = input ('Enter the password again :') luck_num + = 1 # enter the initial password value once and Add 1 p = dic [user] # Find the password corresponding to the input account if password = p: print ('Welcome in !! ') Quit () # exit the program elif luck_num> 2: f = open ('user. log', 'A') # When the number of inputs exceeds three, the user is written to the user. f. write (user + '\ n') f. close () print ('your account has been disabled; contact Customer Service 123456') quit () # exit the program else: print ('enter your password incorrectly ') elif user in dic and user in use: print ('your account % s has been disabled, please change') % user) f. close () else: print ('the account you entered is incorrect. Please enter it again ')