r/ProgrammerHumor • • Feb 18 '24

Meme bruteForceAttackProtection

Post image
42k Upvotes

1.0k comments sorted by

View all comments

180

u/tomer-cohen Feb 18 '24

I don't get how it is protecting against brute force. Can someone explain to the stupid me?

551

u/Eddhuan Feb 18 '24

Generally a brute-force attack will try a new password every time, while a normal user will re-write the same password, thinking he made a typo. So a brute-force attack will, by chance, type the right password, but get the "wrong password" error, then will try other passwords, and thus never get the right answer.

242

u/TheBillsFly Feb 18 '24

Notably it needs to be the first successful login attempt

64

u/Rabid-Chiken Feb 18 '24

The && short circuit can handle that. It doesn't check the second Boolean if the first is false.

Assuming isFirstLoginAttempt has a get function which sets its value to false or something similar

19

u/BlueFireBlaster Feb 18 '24 edited Feb 18 '24

TheBillsFly is correct. The && doesnt handle that. We can safely assume that isFirstLoginAttempt, gets set to false after a failed attemp, and stays that way. A brute force attack is likely to enter tons of passwords wrong before finding the correct one. Thus, isFirstLoginAttempt, will be false, even when CorrectPassword is true for the first time. Thus, the tricky error message wont be output, and a normal log in will be executed.

29

u/Cyber_Fetus Feb 18 '24 edited Feb 19 '24

That would maybe make sense if it were isFirstLogin but that’s a pretty illogical assumption here as a failed login is still an attempt.

2

u/[deleted] Feb 19 '24

But the failed attempts dont get past the correct password check, so while naming wise its weird code wise its fine

→ More replies (5)

16

u/TheBillsFly Feb 18 '24

But that won’t beat a brute force attack unless the brute force happened to get it on the first attempt

18

u/Rabid-Chiken Feb 18 '24

The password has to be correct for the code to reach the isFirstLoginAttempt check because of the short circuit.

The first correct password attempt will trigger isFirstLoginAttempt to be checked, it will be true and the brute force attack will be told the password is wrong. Because the password was correct, the get function for isFirstLoginAttempt is called and sets its value to false. Then a user entering their password the second time around will get through

15

u/TheBillsFly Feb 18 '24

I see, thanks. I feel like that’s less of an intuitive way to understand that second variable though.

5

u/Rabid-Chiken Feb 18 '24

For sure, like you said earlier the name of the variable should include successful for better readability at least

→ More replies (1)

8

u/KingAemon Feb 18 '24

Except as far as I can't tell, isFirstLoginAttempt isnt a function, just a variable - presumably a Boolean. While I don't know every language, this just doesn't compute for most things Im aware of. And also, there are plenty of languages where the code won't even short circuit and would compute both of the values anyway even if they were function calls. It took me way too long to understand what the code was "supposed' to be doing because of these things.

→ More replies (9)

2

u/ADHD-Fens Feb 18 '24

The get function sets the value it checks? Oh god.

2

u/christmas54321 Feb 18 '24

Why would isfirstloginattempt be true? I assume that bool is set to false after the very first login attempt

→ More replies (1)
→ More replies (2)

2

u/knokout64 Feb 18 '24

That's assuming isFirstLoginAttempt is updated only when the value of that boolean is checked, and there's no reason to believe that's the case. The more reasonable assumption would be that isFirstLoginAttempt is updated on its own.

→ More replies (5)

6

u/happyface_0 Feb 18 '24

Now it makes sense to me. Thanks!

6

u/Articunos7 Feb 18 '24

I thought it was the first login attempt in a new account. This makes a lot more sense

2

u/mamaBiskothu Feb 19 '24

So the joke wasn’t logical and funny at all to anyone who has half a brain? Thats funny lol

→ More replies (1)

16

u/tomer-cohen Feb 18 '24

Ooooh I didn't think about how the user will try the same password, I get it now thanks

2

u/AceofToons Feb 19 '24

90% of the time I fail a login it is because I did typo it 😅

0

u/[deleted] Feb 18 '24

[deleted] — view deleted comment

12

u/Eddhuan Feb 18 '24

Like the other comment said, it's probably meant to be isFirstSuccessfulLoginAttempt

→ More replies (10)

2

u/deadlygaming11 Feb 18 '24

Brute force attacks are all about trying different passwords until you get the correct one. It's like getting a 4 digit padlock and then trying all the numbers until it unlocks.

Sites protect themselves against this by only allowing you to get a password wrong so many times before they lock your account or as this meme shows, telling you that the password is wrong the first time you try it. This meme is basically just saying that you will be told that you're wrong the first time you enter the password as this will cause a brute force program to move on.

→ More replies (2)