Ask Your Question
3

How to make usernames not case sensitive?

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

Toms gravatar image

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

Comments

Interesting to have an answer for this issue

Mustafa gravatar imageMustafa ( 2013-08-07 22:01:42 -0600 )edit

1 Answer

Sort by » oldest newest most voted
0

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

wdmytriy gravatar image

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
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

Stats

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

Seen: 1,257 times

Last updated: Dec 20 '13