#!/uer/bin/env python#_*_ coding:utf-8 _*_ImportSysretry_limit= 3Retry_count=0account_file='Accounts.txt'Lock_file='Account_lock.txt' whileRetry_count < retry_limit:#loop body limit 3 times executionusername= Raw_input ('\033[32; Username: \033[0m')#Enter user nameLock_check = open (Lock_file)#Open locked File forLineinchlock_check.readlines (): line= Line.split ()#the loop lock file is compared to the user name entered ifUesrname = = Line[0]:#Determine user name of user input and lock file first element = =Sys.exit ('\031[31; User%s is locked!\033[0m'%username) Password= Raw_input ('\033[32; Password: \033[0m')#Enter passf = File (Account_file,'r+') Match_flag=False forLineinchF.readlines ():#cyclic ACC file,User,password = Lin.strip ('\ n'). Split ()#split the accounts file to filter line breaks, assign to user, and PSS to list ifUsername = = User andPassword = = Password:#judgment: The input use equals the user in ACC and PSS equals the input pss in the list Print('match!'), username Match_flag=True Breakf.close ()ifMatch_flag = = False:#The interpretation flag bit, which does not match by default. #determine whether user input and pass matches the file, do not deserve to continue the loop, match on the exit. Print 'User unmatched!'Retry_count+=1Else : Print('welcom to in Feifei blog system!')Else: Print("You are locked!") F=file (Lock_file,'AB') F.write (username) f.close ()
Write the Login interface 1. Enter the username and password 2. After successful authentication, welcome information is displayed 3. The error three times after the lock
Python exercise (1): Login