From dd7b66fa2848840951bf0a9c67fcf7aaf4156dcd Mon Sep 17 00:00:00 2001 From: Choongmin Lee Date: Tue, 1 Apr 2014 15:12:45 +0900 Subject: [PATCH] Fix PasswordType This commit fixes an error when hex_md5 and other schemes that does not have max_salt_size. This kind of schemes are needed to migrate from very old and stupid databases. --- sqlalchemy_utils/types/password.py | 2 +- tests/types/test_password.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sqlalchemy_utils/types/password.py b/sqlalchemy_utils/types/password.py index bd589ab..6820d24 100644 --- a/sqlalchemy_utils/types/password.py +++ b/sqlalchemy_utils/types/password.py @@ -143,7 +143,7 @@ class PasswordType(types.TypeDecorator, ScalarCoercible): scheme = getattr(__import__('passlib.hash').hash, name) length = 4 + len(scheme.name) length += len(str(getattr(scheme, 'max_rounds', ''))) - length += scheme.max_salt_size or 0 + length += getattr(scheme, 'max_salt_size', 0) length += getattr( scheme, 'encoded_checksum_size', diff --git a/tests/types/test_password.py b/tests/types/test_password.py index 2e363a5..e779402 100644 --- a/tests/types/test_password.py +++ b/tests/types/test_password.py @@ -16,10 +16,11 @@ class TestPasswordType(TestCase): schemes=[ 'pbkdf2_sha512', 'pbkdf2_sha256', - 'md5_crypt' + 'md5_crypt', + 'hex_md5' ], - deprecated=['md5_crypt'] + deprecated=['md5_crypt', 'hex_md5'] )) def __repr__(self):