It is a common recommendation to return "Username or password is incorrect" instead of "Username does not exist" when the given username does not exist and "Password is incorrect" when username exists but password is wrong.

The generally cited reason is that you don't want to provide an attacker with the knowledge that a username exists, to prevent online brute force attacks.

However, if username is used to login, it has to be unique, and therefore you will need to inform the user that a chosen username is taken while they are creating an account. So an attacker can easily determine if a username exists even if you only say "Username or password is incorrect" when logging in.

But even if no signup page exists, or other measures are taken to obscure the existence of usernames on registration, this recommendation still doesn't make sense. Usernames are not designed to be secret. Most people reuse usernames, and they are easy to find. And keeping them secret only improves security so far as it increases the total size of your secret, which can be achieved with longer required passwords.

And moreover, there are better ways to prevent online brute force attacks than longer secrets. Rate limiting users on login, which a properly slow password hashing algorithm like bcrypt already implicitly does, or providing a timeout after many incorrect attempts, solves this problem far better than a longer secret does.

Is there something else I'm missing? Even on this site I see people defending this practice, but I have yet to see a reason that isn't better solved with other methods.

Edit: As a follow-up, if this recommendation really isn't useful, why is it still common? And where did it come from?

  • 2
    FWIW I've seen a suggestion (can't remember where) that when using email addresses as usernames to always display a success message when trying to register, and if the email is already registered the system could just not bother sending a confirmation email, or send an email notifying the user that someone tried to register using their address. – AndrolGenhald Mar 9 '18 at 22:38
  • Usernames are easy to find? Can you explain that? – schroeder Mar 9 '18 at 22:41
  • 3
    You also have to consider that user enumeration isn't just a problem for attacking accounts, it could be a privacy issue. – AndrolGenhald Mar 9 '18 at 22:42
  • 1
    You seem to have skipped over some logic. If "measures are taken to obscure the existence of usernames on registration" then usernames are kept secret, thereby hiding the existence of the username. It's not all about brute force, but privacy is also an issue. – schroeder Mar 9 '18 at 22:43
  • 3
    @PaintingInAir as you said: if usernames are email addresses. Imagine having a user account on a porn site, or a political site, or ... – schroeder Mar 9 '18 at 23:13

Sometimes there is a legitimate reason for such a protection. To give one example I've personally observed (details elided), the website for a medical provider that specializes in a particular kind of treatment (possibly something stigmatized, like sex reassignment or hormone replacement, suicide or drug addiction counseling, abortion, STI treatment, etc.) should definitely have such protections, because merely knowing whether somebody has an account with the provider constitutes a breach of patient confidentiality (in practice, whether or not in law).

Of course, you also need to protect the registration page, in that case - maybe the registration page just never shows an error, merely says "check your email for next steps" whether or not the user is in the system, or perhaps registration requires some private info in addition to the usual email address+password - and all the other avenues of detecting existent accounts (forgot password pages, etc.). That's totally doable, though.

The same principle can be applied to other things where privacy is desired. Online dating services, "adult" toy/movie stores, any kind of social site where users are always under pseudonyms, specialized legal services, any kind of problem-reporting or similar service where somebody might want to retaliate (for example, whistleblower sites), and so on.

When you get right down to it, there's relatively few scenarios where you wouldn't prefer to have such protections (an explicitly non-anonymous social networking/collaboration/etc. site is the only class that immediately comes to mind). For most sites, it's probably not that big of a deal, but in general, unless you have a reason to make it clear who all is using your site, you should try to avoid leaking usernames. Enough people prefer privacy that it's at least worth keeping in mind, and even though in theory it should be the user's job to ensure they aren't using usernames/email addresses traceable to them across multiple sites, in practice people are bad at / don't know how to do that.

EDIT: I didn't read all the comments first; @schroeder gets it.

  • It sounds like this is less a security (as in preventing unauthorized access to accounts) concern, as much as it is a privacy concern. And then, it is only effective when paired with similar protections on registration. Unfortunately, it sounds like you can only obscure the existence of a user on registration if email is used for login and usernames are non-unique, because you will need to inform the user that a username is taken if usernames must be unique. – JustinLovinger Mar 10 '18 at 23:42
  • Privacy is basically a subset of preventing information disclosure, which is itself a subset of security. There may be elements of privacy that are unrelated to security but I don't think this is one of them. As for uniqueness, you can absolutely still have unique usernames. Did you miss the part where I said maybe the registration page just never shows an error, merely says "check your email for next steps" whether or not the user is in the system, or perhaps registration requires some private info in addition to the usual email address+password? Unique IDs matter, and it's not that hard. – CBHacking Mar 11 '18 at 1:17
  • That is true, you can still use the email approach if usernames are used for login, but only if registration requires an email address. – JustinLovinger Mar 11 '18 at 3:35
  • Leaving aside the question of when you last registered for anything online that didn't require an email address, other forms of contact info (e.g. a phone number or postal address) would also work. – CBHacking Mar 11 '18 at 13:42

What you are missing is the crucial element to the "security theatre" definition: no improved security.

Saying that general guidelines provide no improved security in certain cases does not make the guideline is security theatre. As with any guideline, recommendation, best practice, suggestion, or opinion, there must be a risk assessment, which is what security theatre lacks.

If a guideline, like how to treat messaging for bad passwords, offers no improvement in a particular instance, then make that risk assessment. But if you go against an industry standard, then you must make sure that you have accounted for all the potential risks that you may not have considered (like privacy). If you have accounted for all the threats, then make your best decision.

The only problem I have with your concern about this particular general guideline is why you would not follow it. I'm not sure what is gained by not using this particular messaging. But, if you have a legitimate business case, and the risk assessment warrants it, then make your best decision.

  • Regarding why would not follow this guideline, letting the user know they mistyped their username provides a better user experience. – JustinLovinger Mar 10 '18 at 10:01
  • Can you provide instances where this would improve security, and there is not a better solution? – JustinLovinger Mar 10 '18 at 10:03

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