"Description of the problem:
Read the user name and password from the document to verify the correctness of the user name and password,
Password error three times after the user is locked, not allowed to login
Solution Ideas:
1. Read the user information document and deposit it in the two-dimensional list,
2. Lock-in blacklist required
3. The password can only be entered if the user name is lost, the password is three times the user is locked
‘‘‘
#User_Info存用户名和密码, Lock_info to save the locked user
File = Open (r "User_info.txt", "R")
File2 = open (R "Lock_info.txt", "r+")
user = File.readlines () #读用户名和密码
Black_user =file2.readlines () #存黑名单
_user = []
_black_user = []
#把user_info, txt user information deposit list _user
For info in User:
temp = Info.strip (' \ n ')
Temp2 = Temp.split (' \ t ')
_user.append (TEMP2)
#把user_info, txt user information deposit list _user
For info in Black_user:
temp = Info.strip (' \ n ')
Temp2 = Temp.split (' \ t ')
_black_user.append (TEMP2)
While True:
Username = input ("Please input your username:")
#先判断用户是否在黑名单中
For I in range (len (_black_user)):
If username = = _black_user[i][0]:
Print ("User has been locked")
Exit () # Exit directly
#当不再黑名单时. If you are not in User_info, enter the user name again
For I in range (len (_user)):
if i = = Len (_user)-1 and username! = _user[len (_user)-1][0]:
Print ("username does not exist;")
Break
If username! = _user[i][0]:
Continue
Else
Count = 0 #密码计数器
passwd = input ("Please input your passwd:")
While Count < 3:
if passwd = = _user[i][1]:
Print ("Successfully login in ...")
Exit () #break只是退出while循环, the next for loop will continue, so the login succeeds directly exit () exits the program
Elif Count < 2:
Print ("Wrong passwd.please input again.")
passwd = input ("Please input your passwd:")
Count +=1
Else
Print ("You have tried 3 Times.your acount has been locked ...")
File2.write (_user[i][0] + "\ T" + _user[i][1] + "\ n") #被锁后用户信息读到中
Exit ()
File.close ()
File2.close ()
Python realizes simple user login information confirmation, password error 3 times after the user is locked