mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-22 06:28:41 +02:00
see #103
Work in progress: * New domains admin page, all menus are now at the same level, * Views, models and forms partial refactoring (better code organization).
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import hashlib, crypt, string
|
||||
from random import Random
|
||||
from django.conf import settings
|
||||
from django.template import RequestContext
|
||||
from django.shortcuts import render_to_response
|
||||
@@ -118,3 +120,20 @@ class Singleton(type):
|
||||
cls.instance = super(Singleton, cls).__call__(*args, **kwargs)
|
||||
return cls.instance
|
||||
|
||||
|
||||
def _check_password(password, crypted):
|
||||
scheme = parameters.get_admin("PASSWORD_SCHEME", app="admin")
|
||||
if scheme == "crypt":
|
||||
return crypt.crypt(password, crypted) == crypted
|
||||
if scheme == "md5":
|
||||
return hashlib.md5(password).hexdigest() == crypted
|
||||
return password
|
||||
|
||||
def crypt_password(password):
|
||||
scheme = parameters.get_admin("PASSWORD_SCHEME", app="admin")
|
||||
if scheme == "crypt":
|
||||
salt = ''.join(Random().sample(string.letters + string.digits, 2))
|
||||
return crypt.crypt(password, salt)
|
||||
if scheme == "md5":
|
||||
return hashlib.md5(password).hexdigest()
|
||||
return password
|
||||
|
||||
+1
-21
@@ -1,10 +1,6 @@
|
||||
from django.contrib.auth.models import User
|
||||
from modoboa.admin.models import Mailbox
|
||||
import hashlib
|
||||
import crypt
|
||||
import string
|
||||
from random import Random
|
||||
from modoboa.lib import parameters
|
||||
from modoboa.lib import _check_password
|
||||
|
||||
class SimpleBackend:
|
||||
def authenticate(self, username=None, password=None):
|
||||
@@ -26,19 +22,3 @@ class SimpleBackend:
|
||||
except User.DoesNotExist:
|
||||
return None
|
||||
|
||||
def _check_password(password, crypted):
|
||||
scheme = parameters.get_admin("PASSWORD_SCHEME", app="admin")
|
||||
if scheme == "crypt":
|
||||
return crypt.crypt(password, crypted) == crypted
|
||||
if scheme == "md5":
|
||||
return hashlib.md5(password).hexdigest() == crypted
|
||||
return password
|
||||
|
||||
def crypt_password(password):
|
||||
scheme = parameters.get_admin("PASSWORD_SCHEME", app="admin")
|
||||
if scheme == "crypt":
|
||||
salt = ''.join(Random().sample(string.letters + string.digits, 2))
|
||||
return crypt.crypt(password, salt)
|
||||
if scheme == "md5":
|
||||
return hashlib.md5(password).hexdigest()
|
||||
return password
|
||||
|
||||
Reference in New Issue
Block a user