Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Django email auth backend via @rainerborene
# Django email auth backend
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User
class EmailBackend(ModelBackend):
def authenticate(self, **credentials):
if not 'email' in credentials:
return super(EmailBackend, self).authenticate(**credentials)
user = User.objects.get(email=credentials.get('email'))
if user.check_password(credentials.get('password')):
return user
except User.DoesNotExist:
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.