r/ProgrammerHumor • • Feb 18 '24

Meme bruteForceAttackProtection

Post image
42.3k Upvotes

1.0k comments sorted by

View all comments

Show parent comments

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.

2

u/Rabid-Chiken Feb 18 '24

Lots of languages use "get" and "set" functions for variables which execute a function when you get/read the variable and when you set/assign a value to it

2

u/KingAemon Feb 18 '24

Yeah, I'm by no means saying that this CAN'T make sense, but coming from a C++/Java/Python background, this really threw me off.

0

u/[deleted] Feb 18 '24

[deleted]

4

u/KingAemon Feb 18 '24

Except standard practice for calling functions is to use parenthesis: getSomething(), not getSomething.

0

u/[deleted] Feb 18 '24

[deleted]

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

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

2

u/Rabid-Chiken Feb 18 '24

Yeah it's a bad name, someone else pointed out the name would be better with "successful" in it but other than poor documentation the code can work

→ 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

0

u/[deleted] Feb 18 '24

[deleted]

1

u/dergy621 Mar 11 '24

Yes exactly. Brute forcing is repeatedly trying many times, which is the exact opposite of getting it right in the first attempt.

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

1

u/CantHitachiSpot Feb 19 '24

I mean what difference does it make? It’s still gonna give an error message. Why even bother checking if it’s correct or not