Clean code related to kfet password

This commit is contained in:
Aurélien Delobelle 2017-09-22 23:31:46 +02:00
parent 1d19d1797c
commit e5d19811e8
4 changed files with 46 additions and 14 deletions

View file

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
import hashlib
from django.contrib.auth import get_user_model
from kfet.models import Account, GenericTeamToken
@ -18,12 +15,7 @@ class KFetBackend(object):
return None
try:
password_sha256 = (
hashlib.sha256(password.encode('utf-8'))
.hexdigest()
)
account = Account.objects.get(password=password_sha256)
return account.cofprofile.user
return Account.objects.get_by_password(password).user
except Account.DoesNotExist:
return None

View file

@ -1,3 +1,5 @@
import hashlib
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission
@ -26,3 +28,7 @@ def setup_kfet_generic_user(**kwargs):
codename='is_team',
)
)
def hash_password(password):
return hashlib.sha256(password.encode('utf-8')).hexdigest()