This is not done because of timing attacks, it's done because of cargo-cultism and laziness.
> The error shown isn't to dissuade people from using web pages to try to gain access to accounts - it's because the raw code itself doesn't know which is which
Modern systems store passwords salted and hashed with KDFs. The stored hash must be retrieved before the provided password can be checked as you need the stored hash's work factor and salt, which are stored alongside (/as part of) the hash. Such a system necessarily knows which is which.
I don't follow. Surely the reason to hide usernames is not to prevent a timing attack that would reveal... usernames.
Correct username, correct password: takes 30ms to execute the code
Correct username, incorrect password: takes 15 ms to execute the code
Incorrect username: Takes 7 ms to execute the code.
You fuzz usernames, you get one that takes 15 ms, you know that's a valid username. You then start working the password.
Not necessary on most systems, because we're working at speeds that are measured in nanoseconds, and since we're using networks for many attacks, the delays are unpredictable and measured in (at least) milliseconds.
If anything the timing attacks weaken the argument against hiding usernames.
SELECT "Id", "Hash", "Salt" FROM USERS WHERE "Email" = $input
if (results.length == 0) return -1; //No record, bad user, return early...
if (results["Hash"] != Hash(pwd.trim(), results["Salt"]) return -2; //invalid passwordI don't know if there's a solution to that in the general scheme of things, other than making the variance of query times between no user and some user as small as possible.
IMHO usability is more important. There are other ways to improve security. Rate limiting with < N failed attempts via an IP in under < X minutes.
For that matter, adding a random 500-2000ms timer before returning a failed result would likely be as effective, and not lead to a bad user experience.
Timing attacks are solved by how you implement the backend checking code and not how you present the result to the end user in the most user friendly manner.
http://blog.astrumfutura.com/2010/10/nanosecond-scale-remote...
Network latency variance just means you need to sample more. It doesn't prevent the attack.
The error shown isn't to dissuade people from using web pages to try to gain access to accounts - it's because the raw code itself doesn't know which is which, and writing code that does enables fast-paced timing attacks.