Python-based Job 1---user login

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.