Ticket #8321: hashcompat_authuser.diff
File hashcompat_authuser.diff, 1.6 KB (added by , 16 years ago) |
---|
-
django/contrib/auth/models.py
8 8 from django.utils.translation import ugettext_lazy as _ 9 9 import datetime 10 10 import urllib 11 from django.utils.hashcompat import md5_constructor, sha_constructor 11 12 12 13 UNUSABLE_PASSWORD = '!' # This will never be a valid hash 13 14 … … 28 29 except ImportError: 29 30 raise ValueError('"crypt" password algorithm not supported in this environment') 30 31 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() 47 37 raise ValueError("Got unknown password algorithm type in password.") 48 38 49 39 def check_password(raw_password, enc_password):