requirement:
The user name and password are correct, indicating that the login is successful,
Enter the wrong password three times to lock the account.
Start:
Use two files:
Password account file
File format:
jason 23456
tom 56789
tang 345687
boke 567890
Password lock file format:
tom
jason
flow chart
Code
Used
Dictionary: dict() -- generate a dictionary from the account password in the user file, which can correspond to the user name and password
Generate this format: {username1: password1, username2: password2}
loop
Use cycle counting account and password for three times. After three times of account, it will prompt that there is no exit procedure. If the password is incorrect for three times, it will prompt that the corresponding account is locked
judge
Judge whether the account exists and is locked, and whether the password is correct
#!/usr/local/python/bin/python #-*- coding:utf-8 -*- #Author: Chen Xingxin import os f = open("user.txt","r") f2 = open("lockuer.txt","r") lock_user = f2.readlines() m = f.readlines() z = [] #Enter user name and password as list for i in m: y = i.split() q = z.append(y) print(z) #Corresponding the account password in the user file to the dictionary mode dict1 = dict(z) #For the convenience of understanding the generated dictionary print(dict1) for count in range(4): user = input("Please enter your account:") #Determine whether the user name and password entered exist in the locked file, and exit the program if any for i in lock_user: user_lock = i.strip('\n') if user == user_lock: print("Your account has been locked!!!") exit() #If there is no user name entered in the locked file, judge whether the user exists in the dictionary where the account password is located if user in dict1: print("Your account is entered correctly!!") #The account is stored in the dictionary, the program is executed, and the correct password is entered three times for count_p in range(4): password = input("Please enter your password:") #After entering the password, judge whether the input password matches the account, if so, output the welcome information and exit the program if password == dict1[user]: print("Your password is correct!!!\n Welcome to the system!!!!") exit() else: #If the password is wrong, you will be prompted with the wrong password and the number of times you can enter the password print("The password you entered is wrong!!!\n Please re-enter your password!!!\n You have %s Opportunities"%(3-count_p)) #The password is input three times in total. After the number of times is used, you will be prompted that the password is input too many times. Bing will lock the account and write a book to lock the account file if count_p == 3: print("You have entered too many wrong passwords!!!\n Your account has been locked. Please contact the administrator") f2 = open("lock.txt","a") f2.write(user+"\n") exit() #If it is judged that the account does not exist in the account file, there will be more than three times of input to prompt that the account is incorrect, and the opportunity will be used up, exit the program if count == 3: print("You have entered too many incorrect account times\n Exit program") break else: print("Account does not exist, please re-enter\n You have%s Second chance"%(3-count)) f.close() f2.close()
The above is written temporarily. If you have any questions or other suggestions, please point them out
Thank you