fix: replace passlib with bcrypt directly
This commit is contained in:
@@ -1,20 +1,18 @@
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
import bcrypt
|
||||||
from jose import JWTError, jwt
|
from jose import JWTError, jwt
|
||||||
from passlib.context import CryptContext
|
|
||||||
|
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
|
|
||||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
|
||||||
|
|
||||||
|
|
||||||
def hash_password(password: str) -> str:
|
def hash_password(password: str) -> str:
|
||||||
return pwd_context.hash(password)
|
return bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt()).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
def verify_password(plain: str, hashed: str) -> bool:
|
def verify_password(plain: str, hashed: str) -> bool:
|
||||||
return pwd_context.verify(plain, hashed)
|
return bcrypt.checkpw(plain.encode("utf-8"), hashed.encode("utf-8"))
|
||||||
|
|
||||||
|
|
||||||
def create_access_token(subject: int) -> str:
|
def create_access_token(subject: int) -> str:
|
||||||
@@ -40,4 +38,4 @@ def decode_token(token: str) -> Optional[int]:
|
|||||||
payload = jwt.decode(token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM])
|
payload = jwt.decode(token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM])
|
||||||
return int(payload["sub"])
|
return int(payload["sub"])
|
||||||
except (JWTError, KeyError, ValueError):
|
except (JWTError, KeyError, ValueError):
|
||||||
return None
|
return None
|
||||||
@@ -6,7 +6,7 @@ alembic==1.13.1
|
|||||||
pydantic[email]==2.7.1
|
pydantic[email]==2.7.1
|
||||||
pydantic-settings==2.2.1
|
pydantic-settings==2.2.1
|
||||||
python-jose[cryptography]==3.3.0
|
python-jose[cryptography]==3.3.0
|
||||||
passlib[bcrypt]==1.7.4
|
bcrypt==4.1.3
|
||||||
python-multipart==0.0.9
|
python-multipart==0.0.9
|
||||||
httpx==0.27.0
|
httpx==0.27.0
|
||||||
anthropic==0.25.0
|
anthropic==0.25.0
|
||||||
|
|||||||
Reference in New Issue
Block a user