#!/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 ()
Homework:
Writing the Login interface
Enter User name password
Show welcome message after successful authentication
Three-time error after locking
The first day of the Python start job. The code written by the instructor.