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 @@
import hashlib import hashlib
from django.contrib.auth.forms import PasswordResetForm 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): class HashedEmailPasswordResetForm(PasswordResetForm):
username = forms.CharField(label=_('Username'), max_length=254)
def get_users(self, email): def get_users(self, email):
hashed_email = hashlib.sha256(bytes(email, 'utf-8')).hexdigest() accounts = Account.objects.filter(
accounts = Account.objects.filter(hashed_email=hashed_email) user__username=self.cleaned_data['username']
if accounts.count() > 0: )
return (a.user for a in accounts if a.user.has_usable_password()) return (a.user for a in accounts if a.user.has_usable_password() and
else: (check_password(email, a.hashed_email)
return super().get_users(email) or a.user.email == email))

Loading…
Cancel
Save