python3作业:模拟登录

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python3作业:模拟登录相关的知识,希望对你有一定的参考价值。

__author__ = "bin007"

customer = {}#存储用户信息
#处理用户信息文件
try:
with open(‘login.txt‘,‘r‘,encoding=‘utf-8‘) as f:
for line in f:
customer[line.split()[0]] = [line.split()[1],line.split()[2]]
except:
print(‘用户文件不存在‘)

login_name = input("\033[32;1m请输入用户名-->:\033[0m") #获取用户名
login_secret = input(‘\033[32;1m请输入密码--->:\033[0m‘) #获取用户密码
if customer.get(login_name):
customer_secret = customer.get(login_name)[0]
secret_err = int(customer.get(login_name)[1])
if secret_err < 3:
if login_secret == customer_secret:
print(‘\033[32;1m登录成功\033[0m‘)
else:
print(‘\033[31;1m用户名或密码错误,还剩余%s次机会\033[0m‘%(2-secret_err))
customer.get(login_name)[1] = str(int(customer.get(login_name)[1])+1)
else:
print(‘\033[41;1m用户已被锁定\033[0m‘)
customer.get(login_name)[1] = str(int(customer.get(login_name)[1])+1)
print(customer.get(login_name)[1])
else:
login_new = input(‘\033[31;1m用户不存在是否以当前用户名密码注册(Y/N):\033[0m‘)
if login_new == ‘Y‘ or login_new == ‘y‘:
customer[login_name] = [login_secret,0]
print(‘\033[32;1m注册成功,请登录\033[0m‘)
else:
pass
#更新用户文件
with open(‘login.txt‘,‘w+‘,encoding=‘utf-8‘) as f:
for i in customer:
write_line = (‘%s %s %s‘+‘\n‘)% (i,customer[i][0],customer[i][1])
f.write(write_line)










































以上是关于python3作业:模拟登录的主要内容,如果未能解决你的问题,请参考以下文章

python3之本地文件模拟登录

python3.0 模拟用户登录,三次错误锁定

Day1作业-模拟登录

第一周作业,模拟登录

Python爬虫模拟登录遇到的问题——CSRF防御

html+css+js制作LOL官网,web前端大作业(3个页面+模拟登录+链接)