Ask Your Question

How to make usernames not case sensitive?

asked 2013-07-21 05:56:44 -0600

Toms's avatar

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.

edit retag flag offensive close merge delete


Interesting to have an answer for this issue

Mustafa's avatar Mustafa  ( 2013-08-07 22:01:42 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2013-12-20 04:22:59 -0600

wdmytriy's avatar

Taken from here:
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):
            user = User.objects.get(username__iexact=username)
            if user.check_password(password):
                return user
                return None
        except User.DoesNotExist:
            return None

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

AUTHENTICATION_BACKENDS = ('myproject.myapp.backends.CaseInsensitiveModelBacke
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2013-07-21 05:56:44 -0600

Seen: 1,754 times

Last updated: Dec 20 '13