Skip to content

Instantly share code, notes, and snippets.

@rainerborene
Created September 18, 2010 21:33
Show Gist options
  • Save rainerborene/586056 to your computer and use it in GitHub Desktop.
Save rainerborene/586056 to your computer and use it in GitHub Desktop.
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User
class EmailBackend(ModelBackend):
def authenticate(self, **credentials):
if 'username' 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
@rainerborene
Copy link
Author

Yes, you missed the complete path of your backend. You should use the following pattern: projectname.applicationname.backends.EmailBackend. Remember that Google is your friend ;-)

@thiagosoara
Copy link

thanks dude,

Now i'm getting this(I swear I have researched this one enough on the internet before ask you ;) ):

Exception Value:
Module "goow.myAutenticate" does not define a "EmailBackend" authentication backend

Maybe you'll need:
Django Version: 1.2.5
Exception Type: ImproperlyConfigured
Exception Location: /usr/local/lib/python2.6/dist-packages/django/contrib/auth/init.py in load_backend, line 22
Python Executable: /usr/bin/python2.6
Python Version: 2.6.6

I really appreciate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment