Skip to content

Instantly share code, notes, and snippets.

Last active Sep 30, 2016
What would you like to do?
public interface LoginRepository {
String findHashPassword(String loginId);
public interface LoginService {
boolean login(String loginId, String password) throws AuthenticationException;
public class LoginServiceImpl implements LoginService {
* Serviceから呼び出す下位リポジトリ
* 試験クラスからモック化する
LoginRepository loginRepository;
public boolean login(String loginId, String password) throws AuthenticationException {
String hashPassword = loginRepository.findHashPassword(loginId);
if (hashPassword == null) {
throw new AuthenticationException();
return check(password, hashPassword);
* パスワード平文をmd5に変換してDBから取得した値と比較する
private boolean check(String password, String hashPassword) {
String hash = DigestUtils.md5Hex(password);
return hashPassword.equals(hash);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment