r/linuxquestions • u/JustLemonJuice • Jun 02 '21
Resolved Why does checking a wrong password take longer than accepting the right password?
During login, or when using sudo my password usually gets accepted instantly, if I type it correctly. If I type in a wrong password though, my PC will take 1-2 seconds until it says it's wrong.
Why is that?
4
u/TimurHu Jun 02 '21
If you use Gnome and its login manager, then you can hit the ESC key to make it stop spinning while it is 'checking' the wrong password.
3
u/JustLemonJuice Jun 02 '21
That's good to know, thanks!
Wouldn't this circumvent the anti-bruteforce functionality?
3
u/TimurHu Jun 02 '21
I'm not a security expert so can't answer that. All I know is that when I realize I mistyped my password, I hit ESC and then it lets me retry quicker.
2
37
u/alex_ch_2018 Jun 02 '21
To make it a bit harder to an intruder to login into the system by e.g. iterating over a password dictionary.
0
Jun 02 '21
[deleted]
2
u/istarian Jun 02 '21
The time complexity of most hash algorithms is probably known... And it's probably closely related to password length.
Combined with other pieces of information that aren't secret that might help you discover things that are.
0
Jun 02 '21
[deleted]
0
Jun 02 '21
[deleted]
0
Jun 02 '21
[deleted]
0
Jun 02 '21
[deleted]
2
u/VulcansAreSpaceElves Jun 02 '21
You could do that or, with much fewer lines of code you could add a random delay between 0 and 100,000 microseconds to each password failure and get totally effective protection that doesn't even register as different to a human from the 2 second delay for the prevention of brute force attacks.
1
u/AnAirMagic Jun 02 '21
The "correct" way to do that is to use a constant time algorithm (as the grandparent comment alluded to). Here are some examples. They essentially boil down to looking at the entire string buffer before making the decision, no matter the input size, or when the first mismatch occurs.
14
11
u/PageFault Debian Jun 02 '21
I saw an article some years ago where people were able to determine how close they were to a password based on how long it took to compare.
This is likely irrelevant now with the prevalence of hashing, but the idea is that checking correct password takes longer than checking an incorrect password since it can fail on the first incorrect character.
So, say my password is hunter2
Checking with strcmp( passwd, "abc" ) takes less time to check than strcmp( passwd, "hun" ) since it can fail on first incorrect character. Using this information could shorten the time needed to brute force the password. Adding a small, slightly randomized delay would simultaneously prevent this, and reduce the number of possible attempts per time period on same tty.
12
u/LOLTROLDUDES Jun 02 '21
To prevent bots from trying passwords a lot.
For example, magical 0 ms delay, infinite passwords per second, they're in.
Three second delay, they can only guess one password every three seconds.
4
u/thenebular Jun 02 '21
It's a security feature. The delay is to make brute forcing the password through that input take so long it's not feasible.
6
u/apocalypsedg Jun 02 '21
It's dumb I know but it's too prevent attackers from bruteforcing it. Really annoys me when trying to login, it should be 0.5 to 1 second not like 3 or 5 seconds or whatever ridiculous length they set it as, it makes the whole logging in experience feel slow and clunky.
0
Jun 02 '21
[deleted]
2
u/rw3iss Jun 02 '21
Thank you! ๐
0
Jun 02 '21
[deleted]
1
u/rw3iss Jun 02 '21
Yeah, thanks. Not doing anything serious and am usually home anyway, keep laptop close.
2
u/Kriss3d Jun 02 '21
But a good system should let you do say 5 fast password attempts then double up with 1 second per guess as delay. This way you can get a few attempts and the only way to reset it is either no guessing for say an hour or if you get the right login.
1
Jun 02 '21
[removed] โ view removed comment
1
u/ManInBlack829 Jun 02 '21
A lot of Android phones do 5 attempts per minute. Not saying it's ideal but it's a way of looking at it.
1
1
u/michaelpaoli Jun 03 '21
Why does checking a wrong password take longer
It doesn't. A failed login authentication has been attempted. Most of the time after that an intentional delay is added, to slow down any brute force attempts - e.g. trying lots of passwords in quick succession.
1
u/atsuko_24 Jun 02 '21 edited Jun 02 '21
Key stretching. It makes attacks take much longer, whether it's a shitty acquaintance or snoopy SO who has a few ideas what your password may be, or randos from a dozen countries hitting your server with dictionaries.
-1
u/AssumeACanOpener Jun 02 '21
Ha, call me crazy, but I set up all my local accounts to just automatically log on. I mean, if you get physical access to my machines then I'm already done for. Or sure, I can and do encrypt things, but still, I like convenience for the most part.
4
0
Jun 02 '21
[removed] โ view removed comment
2
u/kcl97 Jun 02 '21
If the /etc is not encrypted, you can boot in through USB and fudge around the /etc/passed and /etc/group files to regain access. In the old days, one can just set the root to no password, but these days, you probably have to be more clever, like granting sudo to a backup account. Obviously, make sure your computer is physically locked down or private data encrypted if your /etc is not.
1
u/Michaelmrose Jun 02 '21
If its unencrypted you can simply modify the boot settings to boot directly into a shell and change the password. This can be locked down but this wouldn't be much protection by itself.
If the system is encrypted as any laptop should be then you try really hard to remember or cry.
250
u/aioeu Jun 02 '21 edited Jun 02 '21
The delay is deliberately added by the underlying PAM module that's doing the password check to make it harder to brute-force login attempts.
It would be nice to not have the delay on a GUI login, and to provide some other rate-limiting tactic (e.g. a 10 second timeout every three invalid password attempts)... but unfortunately that's not how it works.
Edit: Looking in to this a bit further... a GUI login manager (e.g. GDM or SDDM) could override the standard PAM failure delay logic and handle the delay itself in some "smarter" fashion. PAM allows the application to register its own delay function by setting the
PAM_FAIL_DELAYPAM item.