Forums

Changing system image to earlgrey breaks my Django login

Hi - I know I'm very late with a dangermouse > earlgrey post, but I thought I had everything working! Have now realised that it is breaking my login (switching back to dangermouse results in the login working) within my Django app. Any ideas where to begin looking for what to change which could resolve this? Thanks!

If I need to include further information here, let me know what and I can add that too

What happens when you try to login -- do you get an error message, or does it just come back with an invalid username/password kind of thing?

Managed to find the problem with the login - it was somewhere within one of my backend classes. Removing this step from the login process now means I can login, although can now require case sensitive usernames (rather than allowing case insensitive as I'd prefer).

Here's the code I have for that if you have any suggestions, but it's not too vital now because I can get logins working (and I can probably figure out another solution to this eventually)!

from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend

class CaseInsensitiveModelBackend(ModelBackend):
    def authenticate(self, request, username=None, password=None, **kwargs):
        UserModel = get_user_model()
        if username is None:
            username = kwargs.get(UserModel.USERNAME_FIELD)
        if username is None or password is None:
            return
        try:
            user = UserModel._default_manager.get(username__iexact==username)
        except UserModel.DoesNotExist:
            # Run the default password hasher once to reduce the timing
            # difference between an existing and a non-existing user (#20760).
            UserModel().set_password(password)
            return
        if user.check_password(password) and self.user_can_authenticate(user):
            return user

Check your error logs from the time when you had the broken code for tracebacks that you can use to debug why that backend does not work.