1.编写登录接口
需求:
.編寫(xiě)登錄接口
·輸入用戶(hù)名密碼
·認(rèn)證成功后顯示歡迎信息
·輸錯(cuò)三次后鎖定 # 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 語(yǔ)句跳出本次循環(huán),而break跳出整個(gè)循環(huán)。
2.注冊(cè)用戶(hù)完成后,直接顯示login,之前用continue的問(wèn)題是,文件用戶(hù)名沒(méi)有刷新,和讀該文件。
'''
2.修改添加注冊(cè)功能流程圖: ?
.編寫(xiě)登錄接口
·輸入用戶(hù)名密碼
·認(rèn)證成功后顯示歡迎信息
·輸錯(cuò)三次后鎖定 # 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 語(yǔ)句跳出本次循環(huán),而break跳出整個(gè)循環(huán)。
2.注冊(cè)用戶(hù)完成后,直接顯示login,之前用continue的問(wèn)題是,文件用戶(hù)名沒(méi)有刷新,和讀該文件。
'''
2.修改添加注冊(cè)功能流程圖: ?
轉(zhuǎn)載于:https://www.cnblogs.com/druex/p/6550384.html
總結(jié)
- 上一篇: 知道一个数组某个index对应的值 不知
- 下一篇: 查看本机的ip地址