replace passlib with bcrypt

This commit is contained in:
Jakub Miazek 2024-10-07 20:09:43 +02:00
parent 1b0776b8c4
commit 65cd76796b
3 changed files with 1105 additions and 1060 deletions

View File

@ -2,17 +2,14 @@ import uuid
from typing import Any
import bcrypt
from passlib.context import CryptContext
from pydantic import SecretStr
from sqlalchemy import String, LargeBinary, select
from sqlalchemy import String, LargeBinary, select, Column
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import mapped_column, Mapped
from app.models.base import Base
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
class User(Base):
id: Mapped[uuid.UUID] = mapped_column(
@ -21,7 +18,7 @@ class User(Base):
email: Mapped[str] = mapped_column(String, nullable=False, unique=True)
first_name: Mapped[str] = mapped_column(String, nullable=False)
last_name: Mapped[str] = mapped_column(String, nullable=False)
_password: Mapped[bytes] = mapped_column(LargeBinary, nullable=False)
_password: bytes = Column(LargeBinary, nullable=False)
@property
def password(self):
@ -29,13 +26,13 @@ class User(Base):
@password.setter
def password(self, password: SecretStr):
_password_string = password.get_secret_value()
_password_string = password.get_secret_value().encode("utf-8")
self._password = bcrypt.hashpw(
_password_string.encode("utf-8"), bcrypt.gensalt()
_password_string, bcrypt.gensalt()
)
def check_password(self, password: SecretStr):
return pwd_context.verify(password.get_secret_value(), self.password)
return bcrypt.checkpw(password.get_secret_value().encode("utf-8"), self._password)
@classmethod
async def find(cls, database_session: AsyncSession, where_conditions: list[Any]):

2150
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -23,7 +23,7 @@ httptools = "^0.6.1"
rich = "^13.8.0"
pyjwt = {version = "^2.9.0", extras = ["cryptography"]}
redis = "^5.0.8"
passlib = {version = "^1.7.4", extras = ["bcrypt"]}
bcrypt = "^4.2.0"
polars = "^1.6.0"
python-multipart = "^0.0.9"
fastexcel = "^0.11.6"