import time
LoginTime = time.asctime( time.localtime(time.time()) )
print ("time %s" % LoginTime)
count = 0
#LoginName = []
data = ("1.注册新会员","2.会员登录")
for i in range(5):
print (data)
choice = input("请选择:")
if choice.isdigit():
choice = int(choice)
with open('access_file',"r+" ,encoding="utf-8") as f:
user_list = f.read().split()
if choice == 1:
username =input("请输入用户名:")
if username.split():
for item in user_list:
if (username) in item:
print("该用户%s已存在,请注册其它用户名!" % username)
break
else:
pwd = input("请输入密码:")
with open('access_file',"a+" ,encoding="utf-8") as f_write:
f_write.write("%s
%s
"% (username,pwd))
print ("注册成功!")
break
elif choice ==2:
login_name = input("请输入用户名:")
if login_name.split():
with open("fail_file","r+",encoding="utf-8" ) as f_lock,open("login_log","a+")as f_log:
user_lock = f_lock.read().split()
for userLock in user_lock:
if login_name in userLock:
print("该用户已锁定,请联系管理员!")
exit()
with open("access_file","r+",encoding="utf-8" ) as f_loginName:
UserList = f_loginName.read().split()
for user_list2 in UserList:
if login_name in user_list:
for count in range(1,4):
count2 =3 - count
user_passwd = input("请输入密码:")
f_passwd = UserList[UserList.index(login_name)+1]
if user_passwd == f_passwd:
f_log.write("%s,%s登录成功!
"%(LoginTime,login_name))
print("登录成功!")
exit()
elif (user_passwd == f_passwd) == False:
f_log.write("%s,%s密码不对,第%s次登录失败!
"%(LoginTime,login_name,count))
if count2 > 0:
print("%s密码不对,你还有%s次登录机会!"% (login_name,count2))
else:
f_log.write("%s帐号%s登录次数超过%s次,现已锁定!"%(LoginTime,login_name,count))
print("帐号%s登录次数超过%s次,现已锁定!"%(login_name,count))
with open("fail_file","a+" ) as f_lock2:
f_lock2.write("%s
"% login_name)
exit()
if login_name not in user_list:
print("用户%s不存在,请注册或用其它用户登录!"% login_name)
break
else:
print("请输入用户名!!!")