1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

multi-auth: Moved check_password implementation to a function and updated the method to use it. This makes it available for future backends to use.

git-svn-id: http://code.djangoproject.com/svn/django/branches/multi-auth@2882 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Joseph Kocherhans 2006-05-10 04:20:53 +00:00
parent 9315633d08
commit 078e2f8d73

View File

@ -6,6 +6,20 @@ import datetime
SESSION_KEY = '_auth_user_id' SESSION_KEY = '_auth_user_id'
def check_password(raw_password, enc_password):
"""
Returns a boolean of whether the raw_password was correct. Handles
encryption formats behind the scenes.
"""
algo, salt, hsh = enc_password.split('$')
if algo == 'md5':
import md5
return hsh == md5.new(salt+raw_password).hexdigest()
elif algo == 'sha1':
import sha
return hsh == sha.new(salt+raw_password).hexdigest()
raise ValueError, "Got unknown password algorithm type in password."
class SiteProfileNotAvailable(Exception): class SiteProfileNotAvailable(Exception):
pass pass
@ -117,14 +131,7 @@ class User(models.Model):
self.set_password(raw_password) self.set_password(raw_password)
self.save() self.save()
return is_correct return is_correct
algo, salt, hsh = self.password.split('$') return check_password(raw_password, self.password)
if algo == 'md5':
import md5
return hsh == md5.new(salt+raw_password).hexdigest()
elif algo == 'sha1':
import sha
return hsh == sha.new(salt+raw_password).hexdigest()
raise ValueError, "Got unknown password algorithm type in password."
def get_group_permissions(self): def get_group_permissions(self):
"Returns a list of permission strings that this user has through his/her groups." "Returns a list of permission strings that this user has through his/her groups."