from werkzeug.security import generate_password_hash, check_password_hash
class User:
''' 该类用于创建用户账号
'''
def init(self, name, email, password):
self.name = name
self.email = email
self.password_hash = self.save_password(password)
def check_email(self, email):
return self.email == email
def save_password(self, password):
'''生成 hash 密码的方法'''
# TODO
return generate_password_hash(password)
def check_password(self, password):
'''检查 hash 密码的方法,返回布尔值'''
# TODO
return check_password_hash(self.password_hash,password)
def __repr__(self):
return ''.format(self.name)
def main():
userList = [] # 创建用户列表
print('■■■■■■■■■■ 欢迎 ■■■■■■■■■■')
while 1:
choose = int(input('''
请选择:
1. 注册
2. 登录
3. 退出
'''))
if choose == 1:
# 进入注册流程
print(' 请输入:')
# 获取用户输入
name = 'guotiao520'
email = '1111111@qq.com'
password = '11113abcd'
newUser = User(name, email, password)
print('用户密码哈希值是:', newUser.password_hash)
userList.append(newUser)
print(newUser)
print(userList)
if choose == 2:
# 进入登录流程
print(' 请输入:')
email = '11111@qq.com'
password = '11111abcd'
# 遍历用户列表,判断email、密码是否正确
# TODO
# print(newUser.check_email(email))
# print(newUser.password_hash)
# print(newUser.check_password(password))
# print(newUser.check_password(password))
# print(newUser.save_password())
if newUser.check_email(email) and newUser.check_password(password) ==True:
print('登录成功')