python 练习一 从文本中读取用户名密码并登录
python练习一
编写一个登陆接口
可以输入用户名密码
认证成功后提示欢迎登陆信息
输错三次后该用户锁定无法登陆
# Author:Roach import sys name_list = open(‘user_pass‘,‘r+‘) # 打开记录用户名密码的文本,文本内格式为:test:test name_text = dict(line.strip().split(":") for line in name_list if line) # 将每行分别读取并作为字典 for i in range(3): username = input("username:") password = input("password:") lock_name = open(‘locked‘, ‘r+‘) # 检测用户是否被锁定 for j in lock_name.readlines(): if username == j.strip(): print("因尝试过多导致{}用户锁定".format(username)) exit(1) # 验证用户名密码是否正确 if password == name_text.get(username): print("Welcome user {name} login...".format(name=username)) break # 输入两次后用户被锁定,将锁定用户写入locked文件中 elif i == 2: lock_name = open(‘locked‘,‘a+‘) lock_name.write(username+‘\n‘) lock_name.close() print("因尝试过多导致{}用户锁定".format(username)) exit(2) else: print(‘‘‘Invalid username or password! ---------剩余尝试次数:{}---------‘‘‘.format(2-i))
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16