Bug fixes: #42, #43, #44

This commit is contained in:
tonio
2010-04-12 10:05:27 +02:00
parent e5e8689f55
commit 1ba8b4b522
4 changed files with 30 additions and 22 deletions
-9
View File
@@ -37,15 +37,6 @@ def exec_pipe(cmd):
code = -1
return code, output
def crypt_password(raw_password):
import md5
import random
salt = md5.new(str(random.random) + str(random.random)).hexdigest()
salt = salt[:5]
hash = md5.new(salt + raw_password).hexdigest()
return "%s$%s$%s" % ("md5", salt, hash)
def _render(request, tpl, user_context):
return render_to_response(tpl, user_context,
context_instance=RequestContext(request))
+16 -4
View File
@@ -1,5 +1,6 @@
from django.contrib.auth.models import User
from mailng.admin.models import Mailbox
from django.conf import settings
import hashlib
import crypt
import string
@@ -25,15 +26,26 @@ class SimpleBackend:
except User.DoesNotExist:
return None
def __get_password_scheme():
try:
scheme = getattr(settings, "PASSWORD_SCHEME")
except AttributeError:
scheme = "crypt"
return scheme
def check_password(password, crypted):
if True:
scheme = __get_password_scheme()
if scheme == "crypt":
return crypt.crypt(password, crypted) == crypted
else:
if scheme == "md5":
return hashlib.md5(password).hexdigest() == crypted
return password
def crypt_password(password):
if True:
scheme = __get_password_scheme()
if scheme == "crypt":
salt = ''.join(Random().sample(string.letters + string.digits, 2))
return crypt.crypt(password, salt)
else:
if scheme == "md5":
return hashlib.md5(password).hexdigest()
return password