更新 database_manager.py
parent
6026eac50e
commit
08790e3e9e
|
|
@ -46,17 +46,18 @@ class DatabaseManager:
|
||||||
|
|
||||||
def valid_login(self, phone_number, password_attempt):
|
def valid_login(self, phone_number, password_attempt):
|
||||||
# SQL查询获取用户的哈希密码,身份和状态
|
# SQL查询获取用户的哈希密码,身份和状态
|
||||||
sql = "SELECT password, identity, status FROM user WHERE phone_number=%s LIMIT 1"
|
sql = "SELECT password, identity, status,nickname FROM user WHERE phone_number=%s LIMIT 1"
|
||||||
result = self.fetch(sql, (phone_number,))
|
result = self.fetch(sql, (phone_number,))
|
||||||
if result:
|
if result:
|
||||||
stored_hash = result[0]['password'] # 假设结果是密码字段
|
stored_hash = result[0]['password'] # 假设结果是密码字段
|
||||||
identity = result[0]['identity'] # 用户身份
|
identity = result[0]['identity'] # 用户身份
|
||||||
status = result[0]['status'] # 用户状态
|
status = result[0]['status'] # 用户状态
|
||||||
|
nickname = result[0]['nickname']
|
||||||
|
|
||||||
# 使用bcrypt进行密码验证
|
# 使用bcrypt进行密码验证
|
||||||
if bcrypt.checkpw(password_attempt.encode('utf-8'), stored_hash.encode('utf-8')):
|
if bcrypt.checkpw(password_attempt.encode('utf-8'), stored_hash.encode('utf-8')):
|
||||||
# 密码匹配,返回登录成功,身份和状态
|
# 密码匹配,返回登录成功,身份和状态
|
||||||
return {'valid': True, 'identity': identity, 'status': status}
|
return {'valid': True, 'identity': identity, 'status': status,'nickname': nickname}
|
||||||
|
|
||||||
# 密码不匹配或用户不存在,返回登录失败
|
# 密码不匹配或用户不存在,返回登录失败
|
||||||
return {'valid': False}
|
return {'valid': False}
|
||||||
|
|
|
||||||
Reference in New Issue