Django

Code

Changeset 9160

Show
Ignore:
Timestamp:
10/06/08 00:14:17 (3 months ago)
Author:
mtredinnick
Message:

Fixed #8321 -- Change django.contrib.auth.models to use django.utils.hashcompat
for consistency with other code. Thanks, magneto.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/contrib/auth/models.py

    r9152 r9160  
     1import datetime 
     2import urllib 
     3 
    14from django.contrib import auth 
    25from django.core.exceptions import ImproperlyConfigured 
     
    58from django.contrib.contenttypes.models import ContentType 
    69from django.utils.encoding import smart_str 
     10from django.utils.hashcompat import md5_constructor, sha_constructor 
    711from django.utils.translation import ugettext_lazy as _ 
    8 import datetime 
    9 import urllib 
    1012 
    1113UNUSABLE_PASSWORD = '!' # This will never be a valid hash 
     
    2830            raise ValueError('"crypt" password algorithm not supported in this environment') 
    2931        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() 
    4637    raise ValueError("Got unknown password algorithm type in password.") 
    4738