* Added documentation

* Ticket #1 implemented
This commit is contained in:
tonio
2009-04-16 18:09:31 +02:00
parent 87881e8365
commit de08808a7f
8 changed files with 81 additions and 13 deletions
+18 -2
View File
@@ -1,6 +1,9 @@
from django.contrib.auth.models import User
from mailng.admin.models import Mailbox
import md5
import hashlib
import crypt
import string
from random import Random
class SimpleBackend:
def authenticate(self, username=None, password=None):
@@ -12,7 +15,7 @@ class SimpleBackend:
mb = Mailbox.objects.get(full_address=username)
except Exception:
return None
if mb.password != md5.new(password).hexdigest():
if not check_password(password, mb.password):
return None
return user
@@ -21,3 +24,16 @@ class SimpleBackend:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None
def check_password(password, crypted):
if True:
return crypt.crypt(password, crypted) == crypted
else:
return hashlib.md5(password).hexdigest() == crypted
def crypt_password(password):
if True:
salt = ''.join(Random().sample(string.letters + string.digits, 2))
return crypt.crypt(password, salt)
else:
return hashlib.md5(password).hexdigest()