模拟登陆

#!/usr/bin/env python
# encoding:utf-8
# __author__: Chen Wei
# date: 2017-05-26
# blog: http://www.cnblogs.com/weiandlu/
#模拟登陆
import getpass
username = input("请输入您的帐号:").strip()
password = getpass.getpass("请输入你的密码:").strip()
count = 1
flag = False
locked_account = ""
with open("account","r",encoding="utf8") as f_read,open("account_locked","a+",encoding="utf8") as f_check:
f_check.seek(0)
for locked_user in f_check:
if username == locked_user.strip():
print("您的帐号已被锁定,请联系管理员解锁!")
exit(0)
else:
continue
for account_pass in f_read:
account,passwd = account_pass.strip().split(",")
if username == account.strip():
while True:
if password == passwd.strip():
print("登陆成功!")
flag = True
break
elif count >= 3:
print("您输入错误密码超过3次,系统将锁定您的帐号!")
locked_account = username
flag = True
break
count += 1
password = input("密码输入错误,请重试!").strip()
if flag:
break
else:
continue
else:
print("您的帐号不存在,请联系管理员进行注册!")
exit(0)
if locked_account:
with open("account_locked", "a", encoding="utf8") as f_write:
f_write.write(''.join(['\n',locked_account]))
posted on 2017-05-26 12:53  Wayne_Chen  阅读(188)  评论(0编辑  收藏  举报