Python code logon Interface

Source: Internet
Author: User

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.
      

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.