需求:
.编写登录接口
·输入用户名密码
·认证成功后显示欢迎信息
·输错三次后锁定
# Author rendelei
while True:
list1 = []
list2 = []
count = int(3)
f = open("login.txt",‘w+’)
for line in f:
hostname = str(line.split('\t')[0])
list1.append(hostname)
password = str(line.split("\t")[1]).strip()
list2.append(password)
username = input("username:")
if username in list1:
while True:
passwd = input("passwd:")
if passwd not in list2:
count = count - 1
print("wrong password,you have {_count} chance to login".format(_count=count))
if count == 0:
print("you have no chance ,the {_username} is been locked,fuck off".format(_username=username))
lockfile = open("lock.txt", 'a+')
lockfile.write("\n"+ username)
lockfile.close()
break
else:
if passwd in list2 and list1.index(username) == list2.index(passwd):
print("welcome {_user_username} login the system".format(_user_username=username))
break
break
else:
message = input("wrong username,do you want to register it?")
if message == "y":
username = input("username:")
passwd = input("passwd:")
f1 = open("login.txt","a+")
f1.write("\n"+username+ "\t")
f1.write(passwd)
f1.flush()
f1.close()
print ("the {_username} is register successful,pls login!".format(_username=username))
continue
else:
print("you have exit the system!")
break
f.close()
'''
1. continue 语句跳出本次循环,而break跳出整个循环。
2.注册用户完成后,直接显示login,之前用continue的问题是,文件用户名没有刷新,和读该文件。
'''
2.修改添加注册功能流程图: