1.重置用户信息
#!/usr/bin/env python#_*_ coding:utf-8 _*_#encoding=utf-8#初始化用户信息#created by xkq#date: 2018
importpickle
user={'xkq':{'pw':'123xk','time':3,'status':'unlock','money':10000},'zq':{'pw':'123','time':3,'status':'unlock','money':10000}}print(user)
f=open('user.pickle','wb')
pickle.dump(user,f)
f.close()#f=open('user.pickle','rb')#a=pickle.load(f)#print(a)#f.close()
2.用户登陆
#!/usr/bin/env python
#_*_ coding:utf-8 _*_
#encoding=utf-8
#功能:用户登陆,密码失败3次,账户将被锁住
#created by xkq
#date: 201803
import pickle,sys,getpass
file='F:\\PyCharm\\script\\day1\\user_login\\user.pickle'
f=open(file,'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(file, '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)
sys.exit()
#return FLAG
return user
if __name__ == '__main__':
logion()
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有