#功能:本地文件存储之实现模拟登录
#用户名和密码保存在一个文件,所存储用户名密码输错三次锁定
import re
def checkUser(username):
lock = open(‘lock.txt‘,)
count = 0
for line in lock:
real_username = line.rstrip("\n")
if real_username == username:
count += 1
if count == 3:
return 0
while True:
username = input("username:")
password = input("password:")
fh = open(‘user.txt‘)
lock = open(‘lock.txt‘, ‘a+‘)
for line in fh:
real_username = re.split(‘:‘,line)[0]
real_password = re.split(‘:‘,line)[1].rstrip("\n")
if real_username == username:
result = checkUser(username)
if result == 0:
print(username+" is Lock")
break
if real_password == password:
print("Good,Login Successful")
break
else:
print("Error")
lock.write(username + "\n")
break
else:
print("No have the",username)
fh.close()
lock.close()