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.
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.
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
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.
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.
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.
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?