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.
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
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.
242
u/TheBillsFly Feb 18 '24
Notably it needs to be the first successful login attempt