1from django.contrib.auth import get_user_model
2from django.contrib.auth.backends import ModelBackend
3
4class EmailBackend(ModelBackend):
5 def authenticate(self, request, username=None, password=None, **kwargs):
6 UserModel = get_user_model()
7 try:
8 user = UserModel.objects.get(email=username)
9 except UserModel.DoesNotExist:
10 return None
11 else:
12 if user.check_password(password):
13 return user
14 return None