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.

33 Upvotes

24 comments sorted by

View all comments

Show parent comment

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