Skip to content

Instantly share code, notes, and snippets.

@langri-sha
Forked from rainerborene/backends.py
Created November 30, 2010 05:49
Show Gist options
  • Save langri-sha/721226 to your computer and use it in GitHub Desktop.
Save langri-sha/721226 to your computer and use it in GitHub Desktop.
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)
try:
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