The first day of getting started with python. The code written by the instructor ., Python instructor
#! /Uer/bin/env python # _ * _ coding: UTF-8 _ * _ import sysretry_limit = 3retry_count = 0account_file = 'accounts.txt 'lock _ file = 'account_lock.txt' while retry_count <retry_limit: # username = raw_input ('\ 033 [32; Username: \ 033 [0m') within three cycles # Enter the username lock_check = open (lock_file) # Open the locked file for line in lock_check.readlines ():
Line = line. split () # Compare the cyclic lock file with the user name entered if uesrname = line [0]: # determine the user name entered by the user and the first element of the User Name of the lock file = sys. exit ('\ 031 [31; User % s is locked! \ 033 [0m' % username) password = raw_input ('\ 033 [32; Password: \ 033 [0m') # enter pass f = file (account_file, 'r + ') match_flag = False for line in f. readlines (): # loop acc file, user, password = lin. strip ('\ n '). split () # split the accounts file and filter the line break, assign the value to the user, and convert it to the list with pss. if username = user and password = password: # judgment: the entered use is equal to the user in acc and the entered pss is equal to the pss print ('match! '), Username match_flag = True break f. close () if match_flag = False: # The flag is interpreted and does not match by default. # Determine whether the user and pass entered by the user match the file. If they do not match the file, the loop continues. If they match the file, the system exits. Print 'user unmatched! 'Retry_count + = 1 else: print ('welcom to in feifei blog system! ') Else: print ("You account is locked! ") F = file (lock_file, 'AB') f. write (username) f. close ()
Job:
Write login interface
Enter user name and password
Welcome information displayed after successful authentication
Lock after three wrong attempts