Skip to content

Instantly share code, notes, and snippets.

@juanriaza
Created November 28, 2011 17:42
Show Gist options
  • Save juanriaza/1401251 to your computer and use it in GitHub Desktop.
Save juanriaza/1401251 to your computer and use it in GitHub Desktop.
from django.core.validators import email_re
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User
class YaraAuthenticationBackend(ModelBackend):
def authenticate(self, identification, password=None):
try:
if email_re.search(identification):
user = User.objects.get(email__iexact=identification)
else:
user = User.objects.get(username__iexact=identification)
if user.check_password(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