When using the standard authentication module in django, failed user authentication is ambiguous. Namely, there seems to be no way to distinguish between the following two scenarios:
- Username was valid, password was invalid
- Invalid username
I think that I would like to display the corresponding messages to the user in these two cases, and not one "username or password was invalid ...".
Anyone has experience with simple ways to do this. The bottom line seems to go right to the lowest level - in the django.contrib.auth.backends.ModelBackend class. The authenticate () method of this class, which takes a username and password as arguments, simply returns a User object if authentication succeeded, or None if authentication failed. Given that this code is at the lowest level (well, the lowest level that is higher than the database code), bypassing it it seems that a lot of code is being thrown.
Is it best to just implement a new authentication server and add it to the AUTHENTICATION_BACKENDS setting? A backend can be implemented that returns a tuple (User, Bool), where the User object is only None if the username does not exist, and Bool is only True if the password was right. This, however, will violate a contract that has a backend with the django.contrib.auth.authenticate () method (which is documented to return a User object on successful authentication and None otherwise).
Maybe it's all worry about nothing? Regardless of whether the username or password was incorrect, the user will probably have to go to the Forgot Password page all the time, so maybe this is all academic. I just can't help but feel ...
EDIT:
, :
, , - . , , . , , , . , , , , , , .