User login program, Applet User Login
Requirements:
1. log on to the user and check whether the user name and password are correct.
2. If the password is incorrect three times, the account will be locked.
3. logon failure due to account locking
Analysis:
1. Enter an account to check whether the account exists, that is, whether the account exists in the account file;
2. If the account exists, check whether the password is correct. If the password is correct, log on successfully. If the password is incorrect, the system prompts you to enter the password again. After three times, the account is locked and a locked file is written;
3. If the account does not exist, the system prompts that the account does not exist.
1 #-*-coding: UTF-8-*-2 # LC 3 username = input ("please input your username :") # enter username 4 # Check whether the username is locked 5 lock_read = open ("lock_file.txt", "r") 6 for lock in lock_read: 7 lock_user = lock. strip () # retrieve the user information in the lock file 8 if username = lock_user: 9 print ("You have been locked! ") 10 break11 else: 12 continue13 lock_read.close () # Read 14 15 if username! = Lock_user: 16 password = input ("please input your password:") # If the user does not lock the file, enter the password 17 with open ("account_file.txt") as user_info: # Open the user account file 18 for account in user_info: # Check whether the input user is 19 account_user = account in the account file. strip (). split ("") [0] 20 account_pass = account. strip (). split ("") [1] 21 if username = account_user: # if the input user name exists in the User File 22 if password = account_pass: 23 print ("welcome to login") # If the password is correct, the logon is successful. 24 break25 else: 26 print ("wrong password! ") # Otherwise, the password is incorrect. Enter the password again, and then enter 27 for count in range () twice ): 28 count = count + 129 password = input ("please input your password:") 30 if password = account_pass: 31 print ("welcome to login ") # if the password entered again is correct, the 32 break33 else: 34 print ("wrong password") 35 if count = 2: # if the password is incorrect three times, then, the lock_write = open ("lock_file.txt", "a +") 37 lock_write.write ("\ n") 38 lock_write.write (username) 39 lock_write.clos E () 40 if username! = Account_user: # If the account does not have this account in the account file, it is suggested that the account does not have this user information 41 print ("No this user ")View Code
Account file:
Account_file.txt
clv 123gl 123
View Code
Lock file:
Lock1__file.txt
1 clv
View Code
I wrote the video for the first time and watched the old boy. After thinking for a long time, I was very happy.