From 05e911ee5b5e1c3ab56e613dd2566413e52376c3 Mon Sep 17 00:00:00 2001 From: Konsta Vesterinen Date: Wed, 30 Oct 2013 15:57:54 +0200 Subject: [PATCH] Refactored password docs --- sqlalchemy_utils/types/password.py | 66 ++++++++++++++++-------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/sqlalchemy_utils/types/password.py b/sqlalchemy_utils/types/password.py index 7e8d10a..fc13772 100644 --- a/sqlalchemy_utils/types/password.py +++ b/sqlalchemy_utils/types/password.py @@ -36,15 +36,42 @@ class Password(object): class PasswordType(types.TypeDecorator, ScalarCoercible): """ - Hashes passwords as they come into the database and allows verifying - them using a pythonic interface :: + PasswordType hashes passwords as they come into the database and allows + verifying them using a pythonic interface. - >>> target = Model() - >>> target.password = 'b' - '$5$rounds=80000$H.............' + All keyword arguments (aside from max_length) are forwarded to the + construction of a `passlib.context.CryptContext` object. - >>> target.password == 'b' - True + The following usage will create a password column that will + automatically hash new passwords as `pbkdf2_sha512` but still compare + passwords against pre-existing `md5_crypt` hashes. As passwords are + compared; the password hash in the database will be updated to + be `pbkdf2_sha512`. + + :: + + + class Model(Base): + password = sa.Column(PasswordType( + schemes=[ + 'pbkdf2_sha512', + 'md5_crypt' + ], + + deprecated=['md5_crypt'] + )) + + + Verifying password is as easy as: + + :: + + target = Model() + target.password = 'b' + # '$5$rounds=80000$H.............' + + target.password == 'b' + # True """ @@ -53,30 +80,7 @@ class PasswordType(types.TypeDecorator, ScalarCoercible): python_type = Password def __init__(self, max_length=None, **kwargs): - """ - All keyword arguments (aside from max_length) are - forwarded to the construction of a `passlib.context.CryptContext` - object. - - The following usage will create a password column that will - automatically hash new passwords as `pbkdf2_sha512` but still compare - passwords against pre-existing `md5_crypt` hashes. As passwords are - compared; the password hash in the database will be updated to - be `pbkdf2_sha512`. :: - - class Model(Base): - password = sa.Column(PasswordType( - schemes=[ - 'pbkdf2_sha512', - 'md5_crypt' - ], - - deprecated=['md5_crypt'] - )) - - """ - - # Bail if passlib is not found. + # Fail if passlib is not found. if passlib is None: raise ImproperlyConfigured( "'passlib' is required to use 'PasswordType'"