summaryrefslogtreecommitdiff
path: root/passlib/ext
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2011-09-19 21:22:14 -0400
committerEli Collins <elic@assurancetechnologies.com>2011-09-19 21:22:14 -0400
commit1d94bf68a9ce60e10d6a7786f3a3b22f7b160e6e (patch)
treee0375f1e7d01b7faf817ca98b555347d42b39526 /passlib/ext
parentf21eb07e034690520afc8e844d91b14314f31a7e (diff)
downloadpasslib-1d94bf68a9ce60e10d6a7786f3a3b22f7b160e6e.tar.gz
added django 0.9 support to passlib.ext.django & tests (such as may be found on GAE)
Diffstat (limited to 'passlib/ext')
-rw-r--r--passlib/ext/django/utils.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/passlib/ext/django/utils.py b/passlib/ext/django/utils.py
index 200bfca..f44f95d 100644
--- a/passlib/ext/django/utils.py
+++ b/passlib/ext/django/utils.py
@@ -23,12 +23,15 @@ __all__ = [
#lazy imports
#===================================================================
+_has_django0 = None # old 0.9 django - lacks unusable_password support
_dam = None #django.contrib.auth.models reference
def _import_django():
- global _dam
+ global _dam, _has_django0
if _dam is None:
import django.contrib.auth.models as _dam
+ from django import VERSION
+ _has_django0 = VERSION < (1,0)
return _dam
#===================================================================
@@ -139,7 +142,7 @@ def set_django_password_context(context=None, get_category=get_category):
:data:`!django.contrib.auth.models.User.password_context`,
for easy access.
"""
- global _django_patch_state, _dam
+ global _django_patch_state, _dam, _has_django0
_import_django()
state = _django_patch_state
User = _dam.User
@@ -181,10 +184,19 @@ def set_django_password_context(context=None, get_category=get_category):
)
#prepare replacements
+ if _has_django0:
+ UNUSABLE_PASSWORD = "!"
+ else:
+ UNUSABLE_PASSWORD = _dam.UNUSABLE_PASSWORD
+
def set_password(user, raw_password):
"passlib replacement for User.set_password()"
if raw_password is None:
- user.set_unusable_password()
+ if _has_django0:
+ # django 0.9
+ user.password = UNUSABLE_PASSWORD
+ else:
+ user.set_unusable_password()
else:
cat = get_category(user) if get_category else None
user.password = context.encrypt(raw_password, category=cat)
@@ -194,7 +206,7 @@ def set_django_password_context(context=None, get_category=get_category):
if raw_password is None:
return False
hash = user.password
- if not hash or hash == _dam.UNUSABLE_PASSWORD:
+ if not hash or hash == UNUSABLE_PASSWORD:
return False
cat = get_category(user) if get_category else None
ok, new_hash = context.verify_and_update(raw_password, hash,
@@ -206,7 +218,7 @@ def set_django_password_context(context=None, get_category=get_category):
def raw_check_password(raw_password, enc_password):
"passlib replacement for check_password()"
- if not enc_password or enc_password == _dam.UNUSABLE_PASSWORD:
+ if not enc_password or enc_password == UNUSABLE_PASSWORD:
raise ValueError("no password hash specified")
return context.verify(raw_password, enc_password)