modify: 依赖更新

This commit is contained in:
2026-04-26 20:44:18 +08:00
parent 450be84020
commit d13ad1f907
7 changed files with 623 additions and 576 deletions
+11 -12
View File
@@ -1,14 +1,13 @@
from passlib.context import CryptContext
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
def verify_password(plain_password: str, hashed_password: str) -> bool:
"""验证密码"""
return pwd_context.verify(plain_password, hashed_password)
# src/chongming/app/core/security.py
import bcrypt
def get_password_hash(password: str) -> str:
"""密码哈希"""
return pwd_context.hash(password)
salt = bcrypt.gensalt()
hashed = bcrypt.hashpw(password.encode('utf-8'), salt)
return hashed.decode('utf-8')
def verify_password(plain_password: str, hashed_password: str) -> bool:
return bcrypt.checkpw(
plain_password.encode('utf-8'),
hashed_password.encode('utf-8')
)
+5 -3
View File
@@ -4,7 +4,7 @@
from typing import Optional
from fastapi import Request
from passlib.context import CryptContext
import bcrypt
from sqlalchemy.ext.asyncio import AsyncSession
from ..model.user import User
@@ -20,7 +20,6 @@ class AuthService:
def __init__(self):
self.jwt_cache = get_jwt_cache()
self.settings = get_config()
self.pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
async def authenticate_user(
self, email: str, password: str, session: AsyncSession
@@ -29,7 +28,10 @@ class AuthService:
user = await UserService.get_user_by_email(email, session)
if not user:
return None
if not self.pwd_context.verify(password, user.hashed_password):
if not bcrypt.checkpw(
password.encode('utf-8'),
user.hashed_password.encode('utf-8')
):
return None
return user