r/AskComputerScience • • Apr 08 '26

Why does it take my computer slightly longer to tell me when I've entered the wrong login password than when I enter the right password?

I've noticed this on both Windows and Linux. If I enter the correct password, it almost instantly starts the login. But if it's the wrong password it takes like a second or so to tell me it's wrong.

34 Upvotes

24 comments sorted by

View all comments

Show parent comment

-2

u/Ronin-s_Spirit Apr 08 '26

I think you don't need to make every check take the same amount of time (which leads to slow behavior if you take a fat timing margin). You just need to run the check on the given password instead of running it on the correct password.

2

u/SlinkyAvenger Apr 09 '26

You don't know what you're talking about.

It's not a matter of checking the correct password versus the given one. The issue here is what happens once the hashes are to be compared to each other.

Let's say the correct password is hunter2 and a character comparison takes ~0.2ms. In a simple "loop through each character of the given password and check against the given character in the known good one, breaking with a failure if they don't match or continuing to the next character until they succeed" check, you'd see the following:

  • A guess of aaaaaa would fail after ~0.2ms. The attacker has a baseline.
  • A guess of baaaaa would also fail after ~0.2ms. The attacker has a good idea that ~0.2ms is the cost of a check.
  • A guess of haaaaa would fail after ~0.4ms. The attacker can assume that at least the first character is correct.
  • A guess of hbaaaa would fail after ~0.4ms. The attacker can continue to assume the first character is correct
  • huaaaa would fail after ~0.6ms. Now the attacker has a good sign that the first two characters are hu.

So on and so forth. That way the brute force aspect is kept to a minimum because the attacker can glean information about its progress in figuring out the password limiting the amount of guesses they need to make.

1

u/Ronin-s_Spirit Apr 10 '26

Sorry bad wording. I meant you loop over the given password (or hash) instead of looking for differeces or the end of the real password, so if you're given 300 chars you always loop 300 chars and if 5 then loop 5. This way you don't need to invent some extended arbitrary delay.

0

u/SlinkyAvenger Apr 10 '26

Your wording conveyed your thought clearly but you're still wrong

1

u/Progribbit Apr 09 '26

but you need the correct password as reference no?

1

u/PressF1ToContinue Apr 09 '26

Only the hash of the correct password is stored on the computer. Then when you try to log in, the hash of your entered password is computed and compared to the stored hash.

1

u/Objective_Mine MSCS, CS Pro (10+) Apr 09 '26

Well, you generally don't want to store original user-provided passwords, so you store a hash of the correct password (plus a random salt) instead, and check a hash against a hash instead of a password against a password. So I don't know if timing attacks are actually that relevant for brute-forcing passwords nowadays. Timing attacks might still be relevant for other secret values of they aren't hashed, though, and they can definitely be relevant in other contexts such as cache-timing attacks.