day09作业01用户登录与验证
Posted 绿洲2017
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了day09作业01用户登录与验证相关的知识,希望对你有一定的参考价值。
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\n%s\n"% (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登录成功!\n"%(LoginTime,login_name))
print("登录成功!")
exit()
elif (user_passwd == f_passwd) == False:
f_log.write("%s,%s密码不对,第%s次登录失败!\n"%(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\n"% login_name)
exit()
if login_name not in user_list:
print("用户%s不存在,请注册或用其它用户登录!"% login_name)
break
else:
print("请输入用户名!!!")
以上是关于day09作业01用户登录与验证的主要内容,如果未能解决你的问题,请参考以下文章