Ticket #8321: hashcompat_authuser.diff

File hashcompat_authuser.diff, 1.6 KB (added by magneto, 16 years ago)
  • django/contrib/auth/models.py

     
    88from django.utils.translation import ugettext_lazy as _
    99import datetime
    1010import urllib
     11from django.utils.hashcompat import md5_constructor, sha_constructor
    1112
    1213UNUSABLE_PASSWORD = '!' # This will never be a valid hash
    1314
     
    2829        except ImportError:
    2930            raise ValueError('"crypt" password algorithm not supported in this environment')
    3031        return crypt.crypt(raw_password, salt)
    31     # The rest of the supported algorithms are supported by hashlib, but
    32     # hashlib is only available in Python 2.5.
    33     try:
    34         import hashlib
    35     except ImportError:
    36         if algorithm == 'md5':
    37             import md5
    38             return md5.new(salt + raw_password).hexdigest()
    39         elif algorithm == 'sha1':
    40             import sha
    41             return sha.new(salt + raw_password).hexdigest()
    42     else:
    43         if algorithm == 'md5':
    44             return hashlib.md5(salt + raw_password).hexdigest()
    45         elif algorithm == 'sha1':
    46             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()
    4737    raise ValueError("Got unknown password algorithm type in password.")
    4838
    4939def check_password(raw_password, enc_password):
Back to Top