Take the 2-minute tour ×
Information Security Stack Exchange is a question and answer site for Information security professionals. It's 100% free, no registration required.

When logging in to a site with wrong user/password credentials, the displayed error is most generally a generic "username or password is incorrect". Looking into some PHP code that handles such login I found a MYSQL request constrained on both the user id and the password hash, making it indeed impossible to determine which of the strings was wrong if the request returns nothing.

Is there some security principle that explains why sites don't rather search for the username, and then match the password, and also why they don't make error messages more specific ("Username not known", "Incorrect password")?

share|improve this question

marked as duplicate by Terry Chia, Adnan, TildalWave, Iszi, Rory Alsop Nov 3 '13 at 18:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

Because you would be giving the attacker information.

If you say "The username is incorrect" or "The password is incorrect" then the attacker knows that one is correct. So, for example, once they guess a username, they can now focus on guessing the password. Rather than 2 unknowns, you have reduced it to just 1 unknown.

Also, for a site where the username is your email, you can determine if people have an account there. If I go to a site and insert your email address and it says "The username is incorrect", then you don't have an account. If it says "The password is incorrect" then I know you have an account there. Now imagine the site is some form of pornography site and you can start to see why this could be a bad approach in terms of what you are revealing to an attacker.

share|improve this answer

Stating that the username is valid enables user enumeration, allowing an attacker to make a list of valid user accounts. For web services where the usernames are email addresses or can be associated with email addresses this could lead to a spear phishing campaign where targets are sent malicious links to a site they really do have an account for. The usernames could also be used for other services like email, file sharing, or shell access, providing even more vectors for exploitation. Or if the user names are linked to real names, the attacker could use such information in a social engineering attack.

Obviously forcing an attacker to guess usernames as well as passwords is preferable.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.