day1-作业
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#Auther:tangnanbing
# read me:
# user_path lock_user_path 为文件名称
#输入用户名 若不存在 则判断不存,若存在 则提示输入密码 密码有三次机会
dict1= {}
dict_lockuser = {}
user_path = r"D:\Python\day1\user.txt"
lock_user_path =r"D:\Python\day1\lockuser.txt"
f = open(user_path,'r')
f_lock_user = open(lock_user_path,'r')
for i in f:
dict1.setdefault(i.split()[0],i.split()[1])
for lock_user in f_lock_user:
dict_lockuser.setdefault(lock_user.split()[0])
UsernameError_ChanceCount = 3
PasswprdError_ChanceCount = 3
print("欢迎登陆系统 您还有: %s 次机会登录系统" % (UsernameError_ChanceCount))
while UsernameError_ChanceCount >0 :
Inputusername = input("Enter your username:")
if Inputusername in(dict1.keys()) and PasswprdError_ChanceCount>0 and Inputusername not in(dict_lockuser.keys()):
Inputpassword = input("Enter your password:")
if Inputpassword == dict1.get(Inputusername):
print ('Wecome, loging ok')
break
else:
#UsernameError_ChanceCount = 3
PasswprdError_ChanceCount -=1
print("用户名输入正确,但是密码错误 您还有: %s 次机会输入密码" %(PasswprdError_ChanceCount))
Inputpassword = input("Enter your password:")
if Inputpassword == dict1.get(Inputusername):
print('Wecome, loging ok')
break
else:
PasswprdError_ChanceCount -= 1
print("用户名输入正确,但是密码错误 您还有: %s 次机会输入密码" % (PasswprdError_ChanceCount))
Inputpassword = input("Enter your password:")
if Inputpassword == dict1.get(Inputusername):
print('Wecome, loging ok')
break
else:
print("你输入的次数太多,账户已被锁定")
with open(lock_user_path,'w') as f:
f.write(Inputusername)
f.close()
UsernameError_ChanceCount = 0
continue
elif Inputusername not in(dict1.keys()):
UsernameError_ChanceCount -=1
print("你的用户名不在此系统内,您还有: %s 次机会登录系统"%(UsernameError_ChanceCount))
else:
print ("您的账户是被锁定账户,不能登陆系统")
break
continue
posted on 2017-12-28 16:54 Sunnynanbing 阅读(127) 评论(0) 编辑 收藏 举报