使用 Python 编写登陆接口

# 使用 Python 编写登陆接口
# Create Date: 2017.10.31 Tuesday
# Author: Eric Zhao
# -*- coding:utf-8 -*-
'''
编写登陆接口
输入用户名密码
认证成功后显示欢迎信息
输错三次后锁定
'''
login_user = input('Please input user name..')
# obj_u = '\''+login_user+'\''
# print(obj_u)
password = input('Please input password..')
users = open('users.txt')
obj_users = eval(users.readline())
# print(type(obj_users))
# blacklist = open('blacklist.txt')
# print(type(blacklist))
'''
line = blacklist.readline()
bl = line.rstrip()
print(bl+' bl')
blacklist.close()
'''
try:
blacklist = open('blacklist.txt')
except FileNotFoundError:
blacklist = open('blacklist.txt','w') # 没有就创建此文件
blacklist = open('blacklist.txt') for line in blacklist:
bl = line.rstrip()
if bl == login_user:
print(login_user + ' is locked!')
blacklist.close()
break
else:
blacklist.close()
count = 0
if login_user in obj_users:
print(login_user + ' is valid account.')
if password == obj_users.get(login_user):
print('Welcome ' + login_user + '.')
else:
while count <= 1:
password = input('The password is wrong,Please input again:')
if password == obj_users.get(login_user):
print('Welcome ' + login_user + '.')
break
count += 1
else:
print('Your account has been locked!')
# 指定打开文件的模式,a为追加
blacklist = open('blacklist.txt','a')
blacklist.write(login_user +'\n')
blacklist.close()
else:
print(login_user + ' does not exist!')
上一篇:监听器 listener 样例


下一篇:this关键字的用法(包括this语句)