def authenticate(self, request, email=None, password=None, username=None):
email = email or username<EOL>try:<EOL><INDENT>email_instance = models.EmailAddress.objects.get(<EOL>is_verified=True, email=email<EOL>)<EOL><DEDENT>except models.EmailAddress.DoesNotExist:<EOL><INDENT>return None<EOL><DEDENT>user = email_instance.user<EOL>if user.check_password(password):<EOL><INDENT>return user<EOL><DEDENT>return None<EOL>
Attempt to authenticate a set of credentials.

Args:
    request:
        The request associated with the authentication attempt.
    email:
        The user's email address.
    password:
        The user's password.
    username:
        An alias for the ``email`` field. This is provided for
        compatability with Django's built in authentication
        views.

Returns:
    The user associated with the provided credentials if they
    are valid. Returns ``None`` otherwise.