mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-12-04 12:24:09 +01:00
Authentication mechanism changed. I don't use Django's builtin
passwords encryption anymore because the default format is something like : <algo>$<salt>$<password> I really think this format is not compatible with external softwares so I use simple hashes.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
from django.contrib.auth.models import User
|
||||
from mailng.admin.models import Mailbox
|
||||
import md5
|
||||
|
||||
class SimpleBackend:
|
||||
def authenticate(self, username=None, password=None):
|
||||
try:
|
||||
user = User.objects.get(username=username)
|
||||
except User.DoesNotExist:
|
||||
return None
|
||||
try:
|
||||
mb = Mailbox.objects.get(full_address=username)
|
||||
except Exception:
|
||||
return None
|
||||
if mb.password != md5.new(password).hexdigest():
|
||||
return None
|
||||
return user
|
||||
|
||||
def get_user(self, user_id):
|
||||
try:
|
||||
return User.objects.get(pk=user_id)
|
||||
except User.DoesNotExist:
|
||||
return None
|
||||
Reference in New Issue
Block a user