Browse Source

add username field, prepare for salted email hash

master
Fr3deric 6 years ago
parent
commit
b84d4ba36d
  1. 19
      bam/forms.py

19
bam/forms.py

@ -1,13 +1,18 @@ @@ -1,13 +1,18 @@
import hashlib
from django.contrib.auth.forms import PasswordResetForm
from bam.models import Account
from django.contrib.auth.hashers import check_password
from django import forms
from django.utils.translation import gettext, gettext_lazy as _
from .models import Account
class HashedEmailPasswordResetForm(PasswordResetForm):
username = forms.CharField(label=_('Username'), max_length=254)
def get_users(self, email):
hashed_email = hashlib.sha256(bytes(email, 'utf-8')).hexdigest()
accounts = Account.objects.filter(hashed_email=hashed_email)
if accounts.count() > 0:
return (a.user for a in accounts if a.user.has_usable_password())
else:
return super().get_users(email)
accounts = Account.objects.filter(
user__username=self.cleaned_data['username']
)
return (a.user for a in accounts if a.user.has_usable_password() and
(check_password(email, a.hashed_email)
or a.user.email == email))

Loading…
Cancel
Save