Skip to content

Commit

Permalink
fix: module 'bcrypt' has no attribute '__about__' (#354)
Browse files Browse the repository at this point in the history
* fix: replace passlib with bcrypt for password hashing and verification

* fix: update lock files with pdm lock
  • Loading branch information
Pradip-p authored Nov 26, 2024
1 parent e3624cb commit a686dec
Show file tree
Hide file tree
Showing 3 changed files with 264 additions and 265 deletions.
13 changes: 7 additions & 6 deletions src/backend/app/users/user_logic.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import time
import bcrypt
import jwt
from app.config import settings
from typing import Any
from psycopg import Connection
from app.db import db_models
from pydantic import EmailStr
from fastapi import HTTPException
from passlib.context import CryptContext
from app.users import user_schemas


pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")


async def create_access_token(subject: str | Any):
expire = int(time.time()) + settings.ACCESS_TOKEN_EXPIRE_MINUTES
refresh_expire = int(time.time()) + settings.REFRESH_TOKEN_EXPIRE_MINUTES
Expand Down Expand Up @@ -53,11 +50,15 @@ def verify_token(token: str) -> dict[str, Any]:


def verify_password(plain_password: str, hashed_password: str) -> bool:
return pwd_context.verify(plain_password, hashed_password)
return bcrypt.checkpw(
plain_password.encode("utf-8"), hashed_password.encode("utf-8")
)


def get_password_hash(password: str) -> str:
return pwd_context.hash(password)
salt = bcrypt.gensalt()
hashed_password = bcrypt.hashpw(password.encode("utf-8"), salt)
return hashed_password.decode("utf-8")


async def authenticate(
Expand Down
Loading

0 comments on commit a686dec

Please sign in to comment.