Document that force_auto_coercion() is required for PasswordType

This commit is contained in:
David Baumgold
2016-06-09 21:31:19 -04:00
parent d712e80ea1
commit 1b89116bc9

View File

@@ -79,13 +79,14 @@ class Password(Mutable, object):
class PasswordType(types.TypeDecorator, ScalarCoercible): class PasswordType(types.TypeDecorator, ScalarCoercible):
""" """
PasswordType hashes passwords as they come into the database and allows PasswordType hashes passwords as they come into the database and allows
verifying them using a pythonic interface. verifying them using a Pythonic interface. This Pythonic interface
relies on setting up automatic data type coercison using the
:func:`~sqlalchemy_utils.listeners.force_auto_coercion` function.
All keyword arguments (aside from max_length) are forwarded to the All keyword arguments (aside from max_length) are forwarded to the
construction of a `passlib.context.LazyCryptContext` object, which construction of a `passlib.context.LazyCryptContext` object, which
also supports deferred configuration via the `onload` callback. also supports deferred configuration via the `onload` callback.
The following usage will create a password column that will The following usage will create a password column that will
automatically hash new passwords as `pbkdf2_sha512` but still compare automatically hash new passwords as `pbkdf2_sha512` but still compare
passwords against pre-existing `md5_crypt` hashes. As passwords are passwords against pre-existing `md5_crypt` hashes. As passwords are
@@ -124,6 +125,9 @@ class PasswordType(types.TypeDecorator, ScalarCoercible):
import flask import flask
from sqlalchemy_utils import PasswordType, force_auto_coercion
force_auto_coercion()
class User(db.Model): class User(db.Model):
__tablename__ = 'user' __tablename__ = 'user'