Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit fb62bcc69e82797782b70288d11789155e4169a5 1 parent c58c1f4
Malcolm Tredinnick authored October 06, 2008

Showing 1 changed file with 9 additions and 18 deletions. Show diff stats Hide diff stats

  1. 27  django/contrib/auth/models.py
27  django/contrib/auth/models.py
... ...
@@ -1,12 +1,14 @@
  1
+import datetime
  2
+import urllib
  3
+
1 4
 from django.contrib import auth
2 5
 from django.core.exceptions import ImproperlyConfigured
3 6
 from django.db import models
4 7
 from django.db.models.manager import EmptyManager
5 8
 from django.contrib.contenttypes.models import ContentType
6 9
 from django.utils.encoding import smart_str
  10
+from django.utils.hashcompat import md5_constructor, sha_constructor
7 11
 from django.utils.translation import ugettext_lazy as _
8  
-import datetime
9  
-import urllib
10 12
 
11 13
 UNUSABLE_PASSWORD = '!' # This will never be a valid hash
12 14
 
@@ -27,22 +29,11 @@ def get_hexdigest(algorithm, salt, raw_password):
27 29
         except ImportError:
28 30
             raise ValueError('"crypt" password algorithm not supported in this environment')
29 31
         return crypt.crypt(raw_password, salt)
30  
-    # The rest of the supported algorithms are supported by hashlib, but
31  
-    # hashlib is only available in Python 2.5.
32  
-    try:
33  
-        import hashlib
34  
-    except ImportError:
35  
-        if algorithm == 'md5':
36  
-            import md5
37  
-            return md5.new(salt + raw_password).hexdigest()
38  
-        elif algorithm == 'sha1':
39  
-            import sha
40  
-            return sha.new(salt + raw_password).hexdigest()
41  
-    else:
42  
-        if algorithm == 'md5':
43  
-            return hashlib.md5(salt + raw_password).hexdigest()
44  
-        elif algorithm == 'sha1':
45  
-            return hashlib.sha1(salt + raw_password).hexdigest()
  32
+
  33
+    if algorithm == 'md5':
  34
+        return md5_constructor(salt + raw_password).hexdigest()
  35
+    elif algorithm == 'sha1':
  36
+        return sha_constructor(salt + raw_password).hexdigest()
46 37
     raise ValueError("Got unknown password algorithm type in password.")
47 38
 
48 39
 def check_password(raw_password, enc_password):

0 notes on commit fb62bcc

Please sign in to comment.
Something went wrong with that request. Please try again.