Made username creation/login case insensitive.
This commit is contained in:
parent
53581637d8
commit
e752c2dd64
5 changed files with 57 additions and 7 deletions
17
src/web/backends.py
Normal file
17
src/web/backends.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
from django.contrib.auth.backends import ModelBackend
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
class CaseInsensitiveModelBackend(ModelBackend):
|
||||
"""
|
||||
By default ModelBackend does case _sensitive_ username authentication, which isn't what is
|
||||
generally expected. This backend supports case insensitive username authentication.
|
||||
"""
|
||||
def authenticate(self, username=None, password=None):
|
||||
try:
|
||||
user = User.objects.get(username__iexact=username)
|
||||
if user.check_password(password):
|
||||
return user
|
||||
else:
|
||||
return None
|
||||
except User.DoesNotExist:
|
||||
return None
|
||||
Loading…
Add table
Add a link
Reference in a new issue