- 输入用户名密码
- 认证成功后显示欢迎信息
- 数错三次后锁定
import getpass
import pickle as p
import ast
count = 0
name = ''
filename1 = 'user.txt'
filename2 = 'user_lock.txt'
list_1 = []
list_2 = []
f1 = open(filename1, 'r')
infos1 = f1.read()
infos1_list = ast.literal_eval(infos1)
f1.close()
f2 = open(filename2, 'r')
infos2 = f2.read()
infos2_list = ast.literal_eval(infos2)
f2.close()
while count < 3:
username = input("username: ")
password = input("password: ")
name = username
list_2.append(name)
list_2.append(password)
if name in infos2_list:
print("lock...")
break
elif list_2 in infos1_list:
print('Wlecome {_name} login...'.format(_name = username))
break
else:
print("Invalid username or password.")
count += 1
else:
print("your account have been locked.")
infos2_list.append(name)
f2 = open(filename2, 'w')
f2.write(str(infos2_list))
f2.close()