Python login interface writing

#coding:utf-8
import getpass,sys
i=0
j=0
while i<3:
    username=raw_input('username:') #Enter username
    life_1=open('account_lock.txt','r+') #Define the file object of the locked file
    life_1list=life_1.readlines() #Assign the content to the list life_1list by line
    for life1 in life_1list:
        user1=life1.strip('\n') #Remove line breaks in each line
        if username==user1: #Determine whether the user is locked
           sys.exit('User %s has been locked, please contact the administrator!'%username)
    life_2=open('account.txt','r') #Define the file object of the user table
    life_2list=life_2.readlines()
    for life2 in life_2list:
        (name,pas)=life2.strip('\n').split() #Remove carriage returns and slices from the username and password in the file, and assign them separately
        if username==name: #Determine whether the entered username is in the user table
           while j<3: #When the username exists, the password is judged
             userpass=raw_input('userpass:')
             if pas==userpass:
                 sys.exit('Login successful!')
             else:
                 print('Incorrect password, please re-enter')     
             j+=1
           if j==3: # Too many wrong passwords, write the username to the lock file
             life_1.write(username+'\n')
             sys.exit(1)
    print('Username is incorrect, please re-enter')
    i+=1
if i==3: #Username input error too many times, exit input
    sys.exit('The user has been locked out because you have entered too many errors!')
life_1.close() #Close the file
life_2.close()

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325238570&siteId=291194637