Extending from the pattern that allows developers to simply set the password property and a setter hashes it on the way in. The User model class has substantial documentation on this. The general approach is to declare the property as:
_password = Column("password",
String,
nullable=True)
followed by exposing the password property as:
@property
def password(self):
return self._password
and finally overriding the setter to hash the password on the way in:
@password.setter
def password(self, password):
self._password = hash_password(password)
The Building Custom Comparator guide outlines how we can override the comparator of hybrid_property in SQLAlchemy, if we adopt this paradigm then we can achieve comparing password as:
user.password == password
as opposed using check_password method
Extending from the pattern that allows developers to simply set the
passwordproperty and a setter hashes it on the way in. TheUsermodel class has substantial documentation on this. The general approach is to declare the property as:followed by exposing the
passwordproperty as:and finally overriding the setter to
hashthe password on the way in:The Building Custom Comparator guide outlines how we can override the comparator of
hybrid_propertyinSQLAlchemy, if we adopt this paradigm then we can achieve comparing password as:as opposed using
check_passwordmethod