Ticket #8647: models.py.diff
File models.py.diff, 1.7 KB (added by , 16 years ago) |
---|
-
.py
old new 7 7 from django.db.models.manager import EmptyManager 8 8 from django.contrib.contenttypes.models import ContentType 9 9 from django.utils.encoding import smart_str 10 from django.utils.hashcompat import md5_constructor, sha_constructor 10 from django.utils.hashcompat import md5_constructor, sha_constructor, sha256_constructor 11 11 from django.utils.translation import ugettext_lazy as _ 12 12 13 13 UNUSABLE_PASSWORD = '!' # This will never be a valid hash … … 34 34 return md5_constructor(salt + raw_password).hexdigest() 35 35 elif algorithm == 'sha1': 36 36 return sha_constructor(salt + raw_password).hexdigest() 37 elif algorithm == 'sha256': 38 from django.conf import settings 39 salt = salt + settings.SECRET_KEY 40 return sha256_constructor(salt + raw_password).hexdigest() 37 41 raise ValueError("Got unknown password algorithm type in password.") 38 42 39 43 def check_password(raw_password, enc_password): … … 42 46 encryption formats behind the scenes. 43 47 """ 44 48 algo, salt, hsh = enc_password.split('$') 49 45 50 return hsh == get_hexdigest(algo, salt, raw_password) 46 51 47 52 class SiteProfileNotAvailable(Exception): … … 165 170 166 171 def set_password(self, raw_password): 167 172 import random 168 algo = 'sha 1'173 algo = 'sha256' 169 174 salt = get_hexdigest(algo, str(random.random()), str(random.random()))[:5] 170 175 hsh = get_hexdigest(algo, salt, raw_password) 171 176 self.password = '%s$%s$%s' % (algo, salt, hsh)