login--用户登陆,密码失败3次,账户将被锁住
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了login--用户登陆,密码失败3次,账户将被锁住相关的知识,希望对你有一定的参考价值。
---------------------------------------------userreset.py#!/usr/bin/env python
# coding:utf-8 _
#encoding=utf-8
#初始化用户信息
#created by xuke
#date: 2018
import pickle
user={‘xkq‘:{‘pw‘:‘123xk‘,‘time‘:3,‘status‘:‘unlock‘},‘zq‘:{‘pw‘:‘123‘,‘time‘:3,‘status‘:‘unlock‘}}
print(user)
f=open(‘user.pickle‘,‘wb‘)
pickle.dump(user,f)
f.close()
------------------------------------------------userlogin.py
#!/usr/bin/env python
# coding:utf-8 _
#encoding=utf-8
#功能:用户登陆,密码失败3次,账户将被锁住
#created by xuke
#date: 201803
import pickle,sys,getpass
f=open(‘user.pickle‘,‘rb‘)
user_all=pickle.load(f)
#print(user)
f.close()
‘‘‘
user[‘dq‘]={‘pw‘: 123, ‘time‘: 3, ‘status‘: ‘unlock‘}
user[‘zq‘][‘time‘]=0
user[‘zq‘][‘status‘]=‘lock‘
f=open(‘user.pickle‘,‘wb‘)
pickle.dump(user,f)
f.close()
‘‘‘
def write_user():
#print(user_all)
f = open(‘user.pickle‘, ‘wb‘)
pickle.dump(user_all, f)
f.close()
def logion():
FLAG=False
#print(user_all)
user=input(‘请输入用户名:‘)
while user not in user_all.keys():
print(‘用户名不存在,请重新输入‘)
user = input(‘请输入用户名:‘)
if user == "exit":
sys.exit()
else:
if user_all[user][‘status‘] ==‘unlock‘:
password = input(‘请输入密码:‘)
#password = getpass.getpass(‘请输入密码:‘)
while password != user_all[user][‘pw‘]:
#print(type(user_all[user][‘pw‘]))
user_all[user][‘time‘] -=1
if user_all[user][‘time‘] == 0:
user_all[user][‘status‘] = ‘lock‘
print(‘密码连续输入不正确,用户%s已被锁,请联系400-123456进行解锁。‘ % user)
write_user()
sys.exit()
#print(user_all[user][‘time‘])
print(‘密码不正确,你还有%s次机会会,请重新输入:‘%user_all[user][‘time‘])
# password = getpass.getpass(‘请输入密码:‘)
password = input(‘请输入密码:‘)
if password == ‘exit‘:
write_user()
sys.exit()
else:
user_all[user][‘time‘]=3
print(‘\033[36;1m欢迎登陆\033[0m‘)
write_user()
FLAG = True
else:
print(‘\033[31;1m用户%s已被锁,请联系400-123456进行解锁.\033[0m‘%user)
return FLAG
if__name == ‘main__‘:
logion()
以上是关于login--用户登陆,密码失败3次,账户将被锁住的主要内容,如果未能解决你的问题,请参考以下文章