Tell the user that the username exists but the password is incorrect?
No, if the user knows that the username is correct, this is an enumeration user vulnerability. You let an attacker know which usernames are valid, allowing them to narrow their target range. This would be useful if they later decided to try brute force attack, because they already know that the usernames are correct and now they only need a working password.
Tell the user that there is no such username, but does the password match something?
Definitely not. This means that the attacker now has a valid password and can use any other username enumeration vulnerability on your site to try to find a valid username. Another common name for enumerating a username is a forgotten form of password - many sites report that there is no such username that allows an attacker to refine his list. Alternatively, they can use this password and brute force from it, which can be much simpler, because usernames should not be complicated.
Aside from this, you should keep your passwords salted and hashed using a secure, slow algorithm like bcrypt . This should mean that you cannot practically check if any password matches the one entered.
Can’t I show a common username and password combination?
Yes!
Do I use different status codes for different situations or provide an error JSON payload?
Your JSON can return true or false so that the calling JavaScript knows if authentication has passed. If you have ever created any protection against brute force, this should be done by introducing a delay in the response, and not to block accounts. Hard lock accounts lead to a DoS attack because an attacker could lock a valid account by reusing the wrong password. For this reason, only a true / false answer is really needed to tell the user if they were successful. Even if the account was blocked, I would return a lie, but included in the message that the user should contact technical support if they believe that they should have access with the password provided.
source share