Skip to content

Instantly share code, notes, and snippets.

@tzachz
Created June 6, 2015 14:43
Show Gist options
  • Select an option

  • Save tzachz/ce659af0be7676e23730 to your computer and use it in GitHub Desktop.

Select an option

Save tzachz/ce659af0be7676e23730 to your computer and use it in GitHub Desktop.
Functions should not have side effects (from Clean Code, p.44)
public class UserValidator {
private Cryptographer cryptographer;
public boolean checkPassword(String userName, String password) {
User user = UserGateway.findByName(userName);
if (user != User.NULL) {
String codedPhrase = user.getPhraseEncodedByPassword();
String phrase = cryptographer.decrypt(codedPhrase, password);
if ("Valid Password".equals(phrase)) {
Session.initialize();
return true;
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment