【Python实例】登录验证系统

'''
账户验证系统:
正确文件记录在right.txt
多次登录失败账号记录在lock.txt中
'''

if __name__ == '__main__' :

'''
初始化信息:
wrong_times 当前输入密码错误次数
wrong_max_times 允许输入密码错误次数
account_file 账户密码保存文件
lock_file 小黑屋
'''
wrong_times = 0
wrong_max_times = 3
account_file = 'right.txt'
lock_file = 'lock.txt'
Flag = 1

while Flag:
print("请输入你的账号密码:")
id = input("Please input your id:")
if id == 'quit':
exit()
pwd = input("Please input your pwd:")

with open(lock_file,"a+") as lock:
for aaa in lock.readlines():
if id == aaa.strip().split()[0]:

print("你的账号在小黑屋呢,不能用")
else:
with open(account_file,"r") as right:
if wrong_times < wrong_max_times :
for bbb in right.readlines():
if id == bbb.strip().split()[0] and pwd == bbb.strip().split()[1]:
print("欢迎登录!")
right.close()
else:
wrong_times += 1
else:
lock.write('\n'+id)
lock.close()
print("你的账号已经在小黑屋")
Flag = 0


posted @ 2016-10-30 22:08  StellariLee  阅读(723)  评论(0编辑  收藏  举报