summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-10-06 05:14:17 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-10-06 05:14:17 +0000
commitfb62bcc69e82797782b70288d11789155e4169a5 (patch)
treee92a41092d60c7bcb54fe5b02e052bf012db382c
parentc58c1f43cf4f35088f815692a5410261e21dfc47 (diff)
Fixed #8321 -- Change django.contrib.auth.models to use django.utils.hashcompat
for consistency with other code. Thanks, magneto. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9160 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/auth/models.py27
1 files changed, 9 insertions, 18 deletions
diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py
index 487e1a3cf2..b8c58ebbb3 100644
--- a/django/contrib/auth/models.py
+++ b/django/contrib/auth/models.py
@@ -1,12 +1,14 @@
+import datetime
+import urllib
+
from django.contrib import auth
from django.core.exceptions import ImproperlyConfigured
from django.db import models
from django.db.models.manager import EmptyManager
from django.contrib.contenttypes.models import ContentType
from django.utils.encoding import smart_str
+from django.utils.hashcompat import md5_constructor, sha_constructor
from django.utils.translation import ugettext_lazy as _
-import datetime
-import urllib
UNUSABLE_PASSWORD = '!' # This will never be a valid hash
@@ -27,22 +29,11 @@ def get_hexdigest(algorithm, salt, raw_password):
except ImportError:
raise ValueError('"crypt" password algorithm not supported in this environment')
return crypt.crypt(raw_password, salt)
- # The rest of the supported algorithms are supported by hashlib, but
- # hashlib is only available in Python 2.5.
- try:
- import hashlib
- except ImportError:
- if algorithm == 'md5':
- import md5
- return md5.new(salt + raw_password).hexdigest()
- elif algorithm == 'sha1':
- import sha
- return sha.new(salt + raw_password).hexdigest()
- else:
- if algorithm == 'md5':
- return hashlib.md5(salt + raw_password).hexdigest()
- elif algorithm == 'sha1':
- return hashlib.sha1(salt + raw_password).hexdigest()
+
+ if algorithm == 'md5':
+ return md5_constructor(salt + raw_password).hexdigest()
+ elif algorithm == 'sha1':
+ return sha_constructor(salt + raw_password).hexdigest()
raise ValueError("Got unknown password algorithm type in password.")
def check_password(raw_password, enc_password):