<commit_before># Based on https://bitbucket.org/jokull/django-email-login/

import re
from uuid import uuid4

from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User
from django.contrib.sites.models import RequestSite, Site

from registration import signals
from registration.models import RegistrationProfile

from invitation.backends import InvitationBackend

from forms import RegistrationForm


class RegistrationBackend(InvitationBackend):
    """
    Does not require the user to pick a username. Sets the username to a random
    string behind the scenes.

    """

    def register(self, request, **kwargs):
        email, password = kwargs['email'], kwargs['password1']

        if Site._meta.installed:
            site = Site.objects.get_current()
        else:
            site = RequestSite(request)
        new_user = RegistrationProfile.objects.create_inactive_user(
            uuid4().get_hex()[:10], email, password, site)
        signals.user_registered.send(
            sender=self.__class__, user=new_user, request=request)
        return new_user

    def get_form_class(self, request):
        """
        Return the default form class used for user registration.

        """
        return RegistrationForm


email_re = re.compile(
    # dot-atom
    r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*"
    # quoted-string
    r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|'
    r'\\[\001-\011\013\014\016-\177])*"'
    # domain
    r')@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$', re.IGNORECASE)


class AuthBackend(ModelBackend):
    """Authenticate using email only"""
    def authenticate(self, username=None, password=<PASSWORD>):
        email = username
        if email_re.search(email):
            user = User.objects.filter(email__iexact=email)
            if user.count() > 0:
                user = user[0]
                if user.check_password(password):<commit_msg>Fix broken email/password login<commit_after># Based on https://bitbucket.org/jokull/django-email-login/

import re
from uuid import uuid4

from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User
from django.contrib.sites.models import RequestSite, Site

from registration import signals
from registration.models import RegistrationProfile

from invitation.backends import InvitationBackend

from forms import RegistrationForm


class RegistrationBackend(InvitationBackend):
    """
    Does not require the user to pick a username. Sets the username to a random
    string behind the scenes.

    """

    def register(self, request, **kwargs):
        email, password = kwargs['email'], kwargs['<PASSWORD>']

        if Site._meta.installed:
            site = Site.objects.get_current()
        else:
            site = RequestSite(request)
        new_user = RegistrationProfile.objects.create_inactive_user(
            uuid4().get_hex()[:10], email, password, site)
        signals.user_registered.send(
            sender=self.__class__, user=new_user, request=request)
        return new_user

    def get_form_class(self, request):
        """
        Return the default form class used for user registration.

        """
        return RegistrationForm


email_re = re.compile(
    # dot-atom
    r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*"
    # quoted-string
    r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|'
    r'\\[\001-\011\013\014\016-\177])*"'
    # domain
    r')@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$', re.IGNORECASE)


class AuthBackend(ModelBackend):
    """Authenticate using email only"""
    def authenticate(self, username=None, password=<PASSWORD>, email=None):
        if email is None:
            email = username
        if email_re.search(email):
            user = User.objects.filter(email__iexact=email)
            if user.count() > 0:
                user = user[0]
                if user.check_password(password):
{'fraction_non_alphanumeric': 0.14130709058793844, 'fraction_numerical': 0.026999747665909665, 'mean_word_length': 2.8410852713178296, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5688841', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1207, 'n_words': 275}