Python code logon Interface
#-*-Coding: UTF-8 -*-
# Author: Mr Gan
Import sys
Limit_time = 3
Loggin_time = 0
While loggin_time <limit_time:
User = input ('\ 033 [31; 1 m username: \ 033 [0m'). strip ()
With open ('account _ lock', 'R') as lock_name:
For lock_line in lock_name:
If user = lock_line.strip ():
Print ('you have been locked ')
If len (user) = 0: # determine whether to enter an empty user Name
Print ('username is not none ')
Continue
Password = input ('\ 033 [31; 1 m password: \ 033 [0m'). strip ()
With open ('account', 'R') as account_name:
Mathch_flag = False # Set the logon authentication flag
For user_line in account_name.readlines ():
Username, passwd = user_line.strip (). split ()
If (user, password) = (username, passwd ):
Print ('% s login success' % user)
Mathch_flag = True # Set the logon authentication flag
Break # Jump Out Of The for Loop
If mathch_flag = False and loggin_time <2: # logon authentication Mismatch
Print ('username or password error, please try again ')
Loggin_time + = 1
Else: # logon authentication successful
With open ('account _ lock', 'a + ') as f:
F. write ('% s \ n' % user)
Print ('you have been locked ')
Break
Code deficiency: when a user is locked, the user name entered for the third time is locked to the file, which does not conform to the logic.