mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-11-27 11:24:28 +01:00
+18
-2
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user