22from typing import Any
33
44import bcrypt
5- from passlib .context import CryptContext
65from pydantic import SecretStr
7- from sqlalchemy import String , LargeBinary , select
6+ from sqlalchemy import String , LargeBinary , select , Column
87from sqlalchemy .dialects .postgresql import UUID
98from sqlalchemy .ext .asyncio import AsyncSession
109from sqlalchemy .orm import mapped_column , Mapped
1110
1211from app .models .base import Base
1312
14- pwd_context = CryptContext (schemes = ["bcrypt" ], deprecated = "auto" )
15-
1613
1714class 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