Ticket #4151: password2.diff
File password2.diff, 2.3 KB (added by , 18 years ago) |
---|
-
django/conf/global_settings.py
318 318 319 319 LOGIN_REDIRECT_URL = '/accounts/profile/' 320 320 321 # Hash algorithm that will be used by admin app if the 322 # hashlib module is available (Python 2.5 onwards). 323 # Allowed values are 'sha1', 'sha224', 'sha256', 'sha384'. 324 PASSWORD_HASH_ALGORITHM = 'sha256' 325 321 326 ########### 322 327 # TESTING # 323 328 ########### -
django/contrib/auth/models.py
17 17 elif algo == 'sha1': 18 18 import sha 19 19 return hsh == sha.new(salt+raw_password).hexdigest() 20 elif algo in ('sha224', 'sha256', 'sha384'): 21 # Note: sha512 could be supported by making password 22 # field of User model longer than 128 chars 23 try: 24 import hashlib 25 except ImportError: 26 # Python version is presumably earlier than 2.5 27 raise ValueError, "%s not supported in this environment." % algo 28 return hsh == hashlib.new(algo, salt+raw_password).hexdigest() 20 29 elif algo == 'crypt': 21 30 try: 22 31 import crypt … … 149 158 return full_name.strip() 150 159 151 160 def set_password(self, raw_password): 152 import sha, random 153 algo = 'sha1' 154 salt = sha.new(str(random.random())).hexdigest()[:5] 155 hsh = sha.new(salt+raw_password).hexdigest() 161 import random 162 try: 163 import hashlib 164 from django.conf import settings 165 algo = settings.PASSWORD_HASH_ALGORITHM 166 salt = hashlib.new(algo, str(random.random())).hexdigest()[:5] 167 hsh = hashlib.new(algo, salt+raw_password).hexdigest() 168 except ImportError: 169 # Python version presumably earlier than 2.5, 170 # so fall back on using SHA-1 hash 171 import sha 172 algo = 'sha1' 173 salt = sha.new(str(random.random())).hexdigest()[:5] 174 hsh = sha.new(salt+raw_password).hexdigest() 156 175 self.password = '%s$%s$%s' % (algo, salt, hsh) 157 176 158 177 def check_password(self, raw_password):