如果登录时,输入密码错误,将锁定此人。
需要通过文件 user.txt 放入每个用户名和密码
需要通过文件 lock.txt 放入锁定用户的用户名
#set encoding=utf-8
user = open('user_np.txt')
account_list = user.readlines()
user.close()
lock_n = False #判断用户输入的用户名是否被锁的标志位
while True:
username = input('please input username:').strip() #strip()函数是忽略空格
if len(username) == 0:
print('输入用户名不能为空')
continue
else:
l = open('lock.txt')
l_list = l.readlines()
l.close()
for j in l_list:
j = j.strip('\n')
if username == j:
print('该用户已经锁定,请联系管理员')
lock_n = True
break
else:
for i in account_list:
i = i.split() #split()函数是对括号中的符号进行切割
if username == i[0]:
for x in range(3):
password = input('please input password:').strip()
if password == i[1]:
print('您可以进入系统')
exit(0)
else:
print('The password is error.')
print('%s ,input password is beyond three times,going to lock'%username)
l = open('lock.txt','a')
l.write(username+'\n') #将要锁的用户名写入锁文件并且换行
l.close()
print('没有这个用户')

