Changeset 9160
- Timestamp:
- 10/06/08 00:14:17 (2 months ago)
- Files:
-
- django/trunk/django/contrib/auth/models.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/contrib/auth/models.py
r9152 r9160 1 import datetime 2 import urllib 3 1 4 from django.contrib import auth 2 5 from django.core.exceptions import ImproperlyConfigured … … 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 datetime9 import urllib10 12 11 13 UNUSABLE_PASSWORD = '!' # This will never be a valid hash … … 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
