Add support for Django > 1.4, get_hexdigest() does not exist anymore

This commit is contained in:
Benjamin Dauvergne 2015-02-03 09:31:47 +01:00
parent 1421ab18dc
commit e069d36ab7
1 changed files with 12 additions and 9 deletions

View File

@ -2,15 +2,18 @@
from django.db import models from django.db import models
from django.contrib.auth.models import get_hexdigest, check_password try:
from django.contrib.auth.models import get_hexdigest, check_password
def crypt_answer(raw):
def crypt_answer(raw): import random
import random algo = 'sha1'
algo = 'sha1' salt = get_hexdigest(algo, str(random.random()), str(random.random()))[:5]
salt = get_hexdigest(algo, str(random.random()), str(random.random()))[:5] hsh = get_hexdigest(algo, salt, raw)
hsh = get_hexdigest(algo, salt, raw) return '%s$%s$%s' % (algo, salt, hsh)
return '%s$%s$%s' % (algo, salt, hsh) except ImportError:
from django.contrib.auth.hashers import make_password, check_password
def crypt_answer(raw):
return make_password(raw, hasher='sha1')
def check_answer(raw, crypted): def check_answer(raw, crypted):