任务要求
- 用户名密码保存在user文件中,黑名单保存在black文件中
- 用户登陆需要输入正确的用户名贺密码,认证成功程序就正常退出
- 认证失败则重新认证,失败三次后,该用户名会被加入黑名单文件
import getpass
f1 = open("user", 'r+')
dict1 = {}
for line in f1.readlines():
a = line.rstrip().split(" ")
dict1[a[0]] = a[1]
flag=1
num=0
while flag == 1:
username = raw_input("请输入您的名字:")
password = raw_input("请输入您的密码:")
f2 = open('black', 'a+')
blacklist = set()
for line in f2.readlines():
a = line.rstrip()
blacklist.add(a)
if username in blacklist:
print "黑名单人员,拒绝你访问"
continue
if username in dict1:
if password == dict1[str(username)]:
print "欢迎!!!"
flag=0
else:
num = num + 1
print "输入密码错误"
if num == 3:
print "尝试太多次,拉黑"
f2.write(username)
f2.write('\n')
f2.close()
num=0
else:
num = num + 1
print "用户不存在"
if num==3:
print "尝试太多次,拉黑"
f2.write(username)
f2.write('\n')
f2.close()
num=0