Requirements:
Enter user name password is correct, prompt login success,
Enter three password errors to lock the account.
Begin:
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 a
Dictionary: dict ()-----Generate a dictionary of account passwords in user files, which can be applied to the username and password
Generate this format: {USERNAME1:PASSWORD1,USERNAME2:PASSWORD2}
Cycle
Use the cycle count account and password three times, the account three times after the prompt does not exist exit program, password three times incorrect prompt corresponding account is locked
Judge
Determine if the account exists and is locked and the password is correct
#!/usr/local/python/bin/python#-*-coding:utf-8-*-#Author: Chen star Heart import OSF = open ("User.txt", "r") F2 = Open (" Lockuer.txt "," r ") Lock_user = F2.readlines () m = F.readlines () z = [] #将用户名密码输入为列表for i in m:y = I.split () q = z.append (y) print (z) #将用户文件中的账户密码对应成字典方式dict1 = Dict (z) #为了方便理解输出生成后的字典print (dict1) for count in range (4): User = input ("Please enter your account:" ) #判断锁定文件中是否存在输入的用户名密码, if there is an exit program for I in Lock_user:user_lock = I.strip (' \ n ') if user = = User_lock: Print ("Your account has been locked!!!") Exit () #如果锁定文件没有输入的用户名则判断用户是否存在于账户密码所在的字典中 if user in Dict1:print ("your account entered correctly!!") #账户存在字典之中, perform a program, three times to enter the correct password for count_p in range (4): Password = input ("Please enter your password:") #输入密码后判断输入的密码是否与账户匹配, if The match outputs the welcome message and exits the program if password = = Dict1[user]: print ("Your password is correct!!! \ n welcome into the system!!!! ") Exit () Else: #输入密码错误则提示密码错误及可输入密码的次数 print ("The password you entered is wrong!!! \ n Please re-enter your password!!! \ nyou still have%s chance. "% (3-count_p)) #密码输入总共三次, the number of times after the use of password input too many times, ice will account locked, write books locked account file if count_p = = 3:print ("You have entered the wrong password too many times!!! \ n Your account has been locked, please contact the administrator "F2 = open (" Lock.txt "," a ") f2.write (user+" \ n ") exit () #判断账 The user does not exist in the account file, then has entered more than three times to prompt the account is incorrect, and the opportunity runs out, exit the program if Count = = 3:print ("You entered the incorrect account number too many \ nthe exit program") Break Else:p Rint ("Account does not exist, please re-enter \ n You also have%s chance"% (3-count)) F.close () F2.close ()
The above is a temporary write, if there are questions or other suggestions, I hope you can point out
Thank you
Python Beginner's account login