Skip to content

Commit db3f728

Browse files
authored
Merge pull request #173 from grillazz/172-passlib-deprecationwarning-crypt-is-deprecated-and-slated-for-removal-in-python-313
replace passlib with bcrypt
2 parents 1b0776b + 65cd767 commit db3f728

File tree

3 files changed

+1105
-1060
lines changed

3 files changed

+1105
-1060
lines changed

app/models/user.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
from typing import Any
33

44
import bcrypt
5-
from passlib.context import CryptContext
65
from pydantic import SecretStr
7-
from sqlalchemy import String, LargeBinary, select
6+
from sqlalchemy import String, LargeBinary, select, Column
87
from sqlalchemy.dialects.postgresql import UUID
98
from sqlalchemy.ext.asyncio import AsyncSession
109
from sqlalchemy.orm import mapped_column, Mapped
1110

1211
from app.models.base import Base
1312

14-
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
15-
1613

1714
class User(Base):
1815
id: Mapped[uuid.UUID] = mapped_column(
@@ -21,21 +18,21 @@ class User(Base):
2118
email: Mapped[str] = mapped_column(String, nullable=False, unique=True)
2219
first_name: Mapped[str] = mapped_column(String, nullable=False)
2320
last_name: Mapped[str] = mapped_column(String, nullable=False)
24-
_password: Mapped[bytes] = mapped_column(LargeBinary, nullable=False)
21+
_password: bytes = Column(LargeBinary, nullable=False)
2522

2623
@property
2724
def password(self):
2825
return self._password.decode("utf-8")
2926

3027
@password.setter
3128
def password(self, password: SecretStr):
32-
_password_string = password.get_secret_value()
29+
_password_string = password.get_secret_value().encode("utf-8")
3330
self._password = bcrypt.hashpw(
34-
_password_string.encode("utf-8"), bcrypt.gensalt()
31+
_password_string, bcrypt.gensalt()
3532
)
3633

3734
def check_password(self, password: SecretStr):
38-
return pwd_context.verify(password.get_secret_value(), self.password)
35+
return bcrypt.checkpw(password.get_secret_value().encode("utf-8"), self._password)
3936

4037
@classmethod
4138
async def find(cls, database_session: AsyncSession, where_conditions: list[Any]):

0 commit comments

Comments
 (0)