1.编写登录接口

需求:
.编写登录接口
·输入用户名密码
·认证成功后显示欢迎信息
·输错三次后锁定
# 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.修改添加注册功能流程图:

 
 
 

转载于:https://www.cnblogs.com/druex/p/6550384.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值