Skip to content

Commit 4885a46

Browse files
committed
passlib replaced with bcrypt for password hashing
1 parent b9edada commit 4885a46

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ alembic = "^1.12.0"
2020
asyncpg = "^0.28.0"
2121
SQLAlchemy-Utils = "^0.41.1"
2222
python-jose = "^3.3.0"
23-
passlib = "^1.7.4"
2423
SQLAlchemy = "^2.0.21"
2524
pytest = "^7.4.2"
2625
python-multipart = "^0.0.6"
@@ -30,6 +29,7 @@ pydantic-settings = "^2.0.3"
3029
redis = "^5.0.1"
3130
arq = "^0.25.0"
3231
gunicorn = "^21.2.0"
32+
bcrypt = "^4.1.1"
3333

3434

3535
[build-system]

src/app/api/dependencies.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from typing import Annotated, Union, Any
22

33
from sqlalchemy.ext.asyncio import AsyncSession
4-
from jose import JWTError, jwt
54
from fastapi import (
65
Depends,
76
HTTPException,
@@ -13,7 +12,6 @@
1312
from ..core.exceptions.http_exceptions import UnauthorizedException, ForbiddenException, RateLimitException
1413
from ..core.db.database import async_get_db
1514
from ..core.logger import logging
16-
from ..core.schemas import TokenData
1715
from ..core.utils.rate_limit import is_rate_limited
1816
from ..core.security import verify_token
1917
from ..crud.crud_rate_limit import crud_rate_limits

src/app/core/security.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import Union, Literal, Dict, Any
22
from datetime import datetime, timedelta
33

4+
import bcrypt
45
from sqlalchemy.ext.asyncio import AsyncSession
5-
from passlib.context import CryptContext
66
from jose import jwt, JWTError
77
from fastapi.security import OAuth2PasswordBearer
88

@@ -17,15 +17,12 @@
1717
REFRESH_TOKEN_EXPIRE_DAYS = settings.REFRESH_TOKEN_EXPIRE_DAYS
1818

1919
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/api/v1/login")
20-
crypt_context = CryptContext(schemes=["sha256_crypt"])
2120

2221
async def verify_password(plain_password: str, hashed_password: str) -> bool:
23-
out: bool = crypt_context.verify(plain_password, hashed_password)
24-
return out
22+
return bcrypt.checkpw(plain_password.encode(), hashed_password.encode())
2523

2624
def get_password_hash(password: str) -> str:
27-
out: str = crypt_context.hash(password)
28-
return out
25+
return bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode()
2926

3027
async def authenticate_user(username_or_email: str, password: str, db: AsyncSession) -> Union[Dict[str, Any], Literal[False]]:
3128
if "@" in username_or_email:

0 commit comments

Comments
 (0)