The two methods below, written in Java, check and validate username and password parameters.
private final String correctUsername = user.getName();
private final String correctPass = user.getPass();
public boolean checkA(String username, String pass) {
return username.equals(correctUsername) && pass.equals(correctPass);
}
public boolean checkB(String username, String pass) {
boolean userCorrect = username.equals(correctUsername);
boolean passCorrect = pass.equals(correctPass);
return userCorrect && passCorrect;
}
Which function is safer, and more importantly, why?
Hint
conditional short-circuitingThree people have already solved this, of which the first two received Lockheed Martin webcam covers.
The answer can be found here: