I have used this code for encoding and decoding the user's password to save in the SQL database PostgreSQL using SQLAlchemy.
In the login process (using verify_password function), I will get ValueError: Invalid salt
import bcrypt
def encode_password(password: str) -> bytes:
"""
Hashing the Password
"""
return bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt())
def verify_password(password: str, hashed_password: str):
"""
Decode the Password
"""
return bcrypt.checkpw(password.encode("utf-8"), hashed_password.encode("utf-8"))
User Model
class User(Base):
"""
User Model
"""
__tablename__ = "users"
id = Column(Integer, primary_key=True)
mobile = Column(String, unique=True, nullable=False)
email = Column(String, unique=True, nullable=False)
password = Column(String, nullable=False)