This commit is contained in:
2026-03-04 22:42:00 +08:00
parent 122ba2b22e
commit 9c8b16871a
2 changed files with 5 additions and 5 deletions
+5 -4
View File
@@ -1,7 +1,7 @@
from datetime import datetime, timedelta
from typing import Optional
from jose import JWTError, jwt
from passlib.context import CryptContext
import bcrypt
from fastapi import Depends, HTTPException, status
from fastapi.security import OAuth2PasswordBearer
from sqlalchemy.ext.asyncio import AsyncSession
@@ -12,18 +12,19 @@ from config.settings import settings
from database.database import get_db_session
from models.database import User, UserRole
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
pwd_context = bcrypt
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/api/auth/login", auto_error=False)
def verify_password(plain_password: str, hashed_password: str) -> bool:
return pwd_context.verify(plain_password, hashed_password)
return pwd_context.checkpw(plain_password.encode('utf-8'), hashed_password.encode('utf-8'))
def get_password_hash(password: str) -> str:
if len(password.encode('utf-8')) > 72:
password = password[:72]
return pwd_context.hash(password)
return pwd_context.hashpw(password.encode('utf-8'), pwd_context.gensalt()).decode('utf-8')
def create_access_token(data: dict, expires_delta: Optional[timedelta] = None) -> str: