Code

Ticket #8647: models.py.diff

File models.py.diff, 1.7 KB (added by sammyrulez, 5 years ago)
Line 
1--- C:\DOCUME~1\SREGHE~1\IMPOST~1\Temp\models.py-revBASE.svn001.tmp.py  mar nov 25 14:59:58 2008
2+++ C:\WORK\libs\djtrunk\django\contrib\auth\models.py  mar nov 25 14:39:26 2008
3@@ -7,7 +7,7 @@
4 from django.db.models.manager import EmptyManager
5 from django.contrib.contenttypes.models import ContentType
6 from django.utils.encoding import smart_str
7-from django.utils.hashcompat import md5_constructor, sha_constructor
8+from django.utils.hashcompat import md5_constructor, sha_constructor, sha256_constructor
9 from django.utils.translation import ugettext_lazy as _
10 
11 UNUSABLE_PASSWORD = '!' # This will never be a valid hash
12@@ -34,6 +34,10 @@
13         return md5_constructor(salt + raw_password).hexdigest()
14     elif algorithm == 'sha1':
15         return sha_constructor(salt + raw_password).hexdigest()
16+    elif algorithm == 'sha256':
17+        from django.conf import settings
18+        salt = salt + settings.SECRET_KEY
19+        return sha256_constructor(salt + raw_password).hexdigest()
20     raise ValueError("Got unknown password algorithm type in password.")
21 
22 def check_password(raw_password, enc_password):
23@@ -42,6 +46,7 @@
24     encryption formats behind the scenes.
25     """
26     algo, salt, hsh = enc_password.split('$')
27+   
28     return hsh == get_hexdigest(algo, salt, raw_password)
29 
30 class SiteProfileNotAvailable(Exception):
31@@ -165,7 +170,7 @@
32 
33     def set_password(self, raw_password):
34         import random
35-        algo = 'sha1'
36+        algo = 'sha256'
37         salt = get_hexdigest(algo, str(random.random()), str(random.random()))[:5]
38         hsh = get_hexdigest(algo, salt, raw_password)
39         self.password = '%s$%s$%s' % (algo, salt, hsh)