Skip to content
This repository has been archived by the owner on Oct 18, 2022. It is now read-only.

When deactivated user tries to log in it displays that credentials are invalid. #133

Open
acolazo opened this issue Feb 21, 2022 · 3 comments

Comments

@acolazo
Copy link

acolazo commented Feb 21, 2022

When deactivated user tries to log in it displays that credentials are invalid instead of indicating that the user is deactivated.

Digging into the code the class AuthenticationForm has the following code:

self.user_cache = authenticate(email=email, password=password)
if self.user_cache is None:
    raise forms.ValidationError(
        self.error_messages['invalid_login'],
        code='invalid_login',
        params={'email': self.email_field.verbose_name},
    )
elif not self.user_cache.is_active:
    raise forms.ValidationError(
        self.error_messages['inactive'],
        code='inactive',
    )

It doesn't get to the elif because authenticate returns None when the user is deactivated.

@nstuardod
Copy link
Member

Actually, the issue occurs at ModelBackend. It is made to reject deactivated users by default.
This is more a feature than a bug, because it hides to external users the fact the account
exists.

@acolazo
Copy link
Author

acolazo commented Apr 5, 2022

The bug is that there is an unreachable block of code to raise an error message that will never occur. The ModelBackend works as intended but the elif block i referenced will never be executed.

The block of code should either be reachable and show the inactive error message, or the elif block should be removed and there shouldn't be an inactive error message.

@nstuardod
Copy link
Member

To make it reachable, you need a different backend such as AllowAllUsersModelBackend. The default one won't work.
https://docs.djangoproject.com/en/2.2/topics/auth/default/#django.contrib.auth.forms.AuthenticationForm

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants