Closed AnishMulay closed 2 hours ago
The code in the UserLogin API was comparing the user-entered password with the stored password using:
if password == user.password:
Django stores passwords in a hashed format, and direct comparisons with plaintext passwords are not valid.
The correct way to compare passwords in Django is to use the check_password function provided by django.contrib.auth.hashers
, which hashes the input password and securely checks it against the stored hash.
The login API was failing to correctly validate user credentials. Specifically, the issue occurred because the plaintext password entered by the user was being directly compared with the hashed password stored in the database. Since Django hashes passwords for security purposes, a direct comparison between plaintext and hashed values will always fail unless the database is insecurely storing passwords in plaintext (which is not recommended).