Ticket #4151: password.diff
File password.diff, 1.7 KB (added by , 18 years ago) |
---|
-
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 algo = 'sha256' 165 salt = hashlib.new(algo, str(random.random())).hexdigest()[:5] 166 hsh = hashlib.new(algo, salt+raw_password).hexdigest() 167 except ImportError: 168 # Python version presumably earlier than 2.5, 169 # so fall back on using SHA1 hash 170 import sha 171 algo = 'sha1' 172 salt = sha.new(str(random.random())).hexdigest()[:5] 173 hsh = sha.new(salt+raw_password).hexdigest() 156 174 self.password = '%s$%s$%s' % (algo, salt, hsh) 157 175 158 176 def check_password(self, raw_password):