diff options
-rw-r--r-- | passlib/ext/django/models.py | 15 | ||||
-rw-r--r-- | tox.ini | 10 |
2 files changed, 20 insertions, 5 deletions
diff --git a/passlib/ext/django/models.py b/passlib/ext/django/models.py index 1c74f12..f82e399 100644 --- a/passlib/ext/django/models.py +++ b/passlib/ext/django/models.py @@ -187,11 +187,16 @@ def _apply_patch(): scheme = hasher_to_passlib_name(hasher) kwds = dict(scheme=scheme) handler = password_context.handler(scheme) - # NOTE: django make specify an empty string for the salt, - # even if scheme doesn't accept a salt. we omit keyword - # in that case. - if salt is not None and (salt or 'salt' in handler.setting_kwds): - kwds['salt'] = salt + if "salt" in handler.setting_kwds: + if hasher.startswith("unsalted_"): + # Django 1.4.6+ uses a separate 'unsalted_sha1' hasher for "sha1$$digest", + # but passlib just reuses it's "sha1" handler ("sha1$salt$digest"). To make + # this work, have to explicitly tell the sha1 handler to use an empty salt. + kwds['salt'] = '' + elif salt: + # Django make_password() autogenerates a salt if salt is bool False (None / ''), + # so we only pass the keyword on if there's actually a fixed salt. + kwds['salt'] = salt return password_context.encrypt(password, **kwds) @_manager.monkeypatch(HASHERS_PATH) @@ -133,6 +133,16 @@ deps = commands = nosetests {posargs:passlib.tests.test_ext_django passlib.tests.test_handlers_django} +[testenv:django145] +# NOTE: doing this to detect regression of issue 52, since django < 1.4.6 +# has some slight differences in the hasher classes & tests. +deps = + django==1.4.5 + bcrypt + {[testenv]deps} +commands = + nosetests {posargs:passlib.tests.test_ext_django passlib.tests.test_handlers_django} + [testenv:django14] deps = django<1.5 |