diff --git a/store/app/model.py b/store/app/model.py index 6eeb7936..57294668 100644 --- a/store/app/model.py +++ b/store/app/model.py @@ -51,10 +51,10 @@ def create(cls, email: str, password: str) -> Self: return cls( id=new_uuid(), email=email, + hashed_password=hash_password(password), permissions=None, created_at=now, updated_at=now, - hashed_password=hash_password(password) # Call a function to hash the password ) def update_timestamp(self) -> None: @@ -64,7 +64,6 @@ def verify_email(self) -> None: self.email_verified_at = int(time.time()) - class OAuthKey(RobolistBaseModel): """Keys for OAuth providers which identify users.""" diff --git a/store/app/utils/security.py b/store/app/utils/security.py index 82b97f53..57dfb5f3 100644 --- a/store/app/utils/security.py +++ b/store/app/utils/security.py @@ -1,8 +1,10 @@ import bcrypt + def hash_password(password: str) -> str: salt = bcrypt.gensalt() - return bcrypt.hashpw(password.encode('utf-8'), salt).decode('utf-8') + return bcrypt.hashpw(password.encode("utf-8"), salt).decode("utf-8") + def verify_password(plain_password: str, hashed_password: str) -> bool: - return bcrypt.checkpw(plain_password.encode('utf-8'), hashed_password.encode('utf-8')) + return bcrypt.checkpw(plain_password.encode("utf-8"), hashed_password.encode("utf-8"))