首页 技术 正文
技术 2022年11月23日
0 收藏 774 点赞 2,557 浏览 1521 个字

题目需求:

  1.输入用户名密码

  2.认证成功后显示欢迎信息

  3.输错三次后锁定

#读取注册用户的信息,用户名,密码,输错次数,写入字典中
user={}
with open("DB1",encoding="utf8") as f:
for line in f:
username_list=line.strip().split("|") #username_list--->['egon', '123', '2']
user[username_list[0]]={"name":username_list[0],
"pwd":username_list[1],
"times":username_list[2]}
# print(user) #-->{'egon': {'name': 'egon', 'pwd': '123', 'times': '2'}, 'xuyaping': {'name': 'xuyaping', 'pwd': '123', 'times': '0'}, 'xyy': {'name': 'xyy', 'pwd': '123', 'times': '1'}}#读取黑名单用户,将黑名单用户加入列表中
with open("black_lockname",encoding="utf8") as f1:
black_list=[]
for line in f1:
black_list.append(line.strip())
# print(black_list)while True:
username = input("please input your username:").strip()
passwd = input("please input your passwd:").strip()
#用户在黑名单中
if username in black_list:
print("该用户为黑名单用户,请滚")
break # 用户为注册用户
elif username in user:
user[username]["times"]=int(user[username]["times"])
if user[username]["times"]<3 and passwd==user[username]["pwd"]:
print("登录成功")
user[username]["times"]=0
#将修改后的信息重新写入DB1中
with open("DB1","w",encoding="utf8") as f3:
for i in user:
f3.write(i + "|" + user[i]["pwd"] + "|" + str(user[i]["times"]) + "\n")
break else:
user[username]["times"]+=1
print("登录错误")
# 将修改后的信息重新写入DB1中
with open("DB1", "w", encoding="utf8") as f3:
for i in user:
f3.write(i + "|" + user[i]["pwd"] + "|" + str(user[i]["times"]) + "\n")
if user[username]["times"]==3:
black_list.append(username)
print("账户被锁定")
# 将修改后的信息重新写入black_lockname中
with open("black_lockname","w",encoding="utf8") as f4:
for j in black_list:
f4.write(j+ "\n")
break #用户不是注册用户
else:
print("该用户没有注册")
break
xuyaping|123|0
egon|123|1
xuyuanyuan|123|2

DB1

alex

black_lockname

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,958
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,482
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,328
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,111
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,743
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,777