First time here? Check out the FAQ!
3

How to make usernames not case sensitive?

  • retag add tags

Is it possible to make user names not case sensitive?

It may cause confusion, if there are users: Toms, toms, tOms, toMs, TomS, TOms, ...

Furthermore user are sometimes confused, when they are trying to log in and they forget that their username starts with a capital letter.

Toms's avatar
767
Toms
asked 2013-07-21 05:56:44 -0500
edit flag offensive 0 remove flag close merge delete

Comments

Interesting to have an answer for this issue

Mustafa's avatar Mustafa (2013-08-07 22:01:42 -0500) edit
add a comment see more comments

1 Answer

0

Taken from here: shopfiber.com/case-insensitive-username-login-in-django/
Add custom proxy to model authentication backend:

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

Once you have the model defined, edit your settings.py and specify “AUTHENTICATION_BACKENDS”.

AUTHENTICATION_BACKENDS = ('myproject.myapp.backends.CaseInsensitiveModelBacke
wdmytriy's avatar
13
wdmytriy
answered 2013-12-20 04:22:59 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments