Job: Writing the Login interface
- Enter User name password
- Show welcome message after successful authentication
- Three-time error after locking
Import sys, OS, getpass
Os.system (' Clear ')
i =0
While I <3:# The exception does not exceed 3 times to keep on circulating
Name =Input"Please enter user name:")
Lock_file =Open' A.docx ',' r+ ')# When the user enters the user name, open the lock file to check if the user is already lock
Lock_list = Lock_file.readlines ()
For Lock_lineIn Lock_list:# loop Lock
Lock_line = Lock_line.strip (‘\ n‘)# Remove Line break
Print (Lock_line.strip ())# Explain the role of this
If name = = Lock_line:# If you lock, just quit.
Sys.exit (' User%s has been locked, exit '% name '
User_file =Open' A.docx ',' R ')# Open Account File
User_list = User_file.readlines ()
Print (User_file.readlines ())
For User_lineIn User_list:# traverse the account file
(user, Password_line) = User_line.strip (‘\ n'). Split ()# Get account and password information separately
If name = = User:# If the user name matches correctly
j =0
While J <3:# Keep Looping as long as the user's password doesn't exceed 3 times
Password = Getpass.getpass (' Please enter your password: ')# Enter hidden password
if password = = Password_line:# password is correct, prompt Welcome to login
Print' Welcome to login management Platform, user%s '% name '
Sys.exit (0)# Normal Exit
Else
Lock_file.write (name +‘\ n‘)# password is entered three times, append the user to the lock file
Sys.exit (" user%s reached the maximum number of logins, will be locked out and exit '% name ')
Span style= "color: #000080; Font-weight:bold ">else:
pass # When the user does not match, skip and continue looping
else:
Sys.exit (" user%s does not exist, exit '% name ') # the user entered three errors, the exception exits
Lock_file.close () Span style= "color: #808080; Font-style:italic "># close lock file
User_file.close () # Close the account file
Python-based Job 1---user logon