Last Updated: February 25, 2016
·
998
· cingusoft

Django Email Authentication Backend

class EmailBackend:
    supports_object_permissions = False
    supports_anonymous_user = False
    supports_inactive_user = False

    def authenticate(self, username=None,password=None):
        try:
            user = User.objects.get(email=username)
            if not user.check_password(password):
                return None
        except User.DoesNotExist:
            return None
        return user

    def get_user(self, user_id):
        try:
            return User.objects.get(pk=user_id)
        except User.DoesNotExist:
            return None

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

Account takeover often starts in the browser, on the login page itself. A malicious script can read credentials, tokens, or one-time codes as the person types them.

Security insights from Cside