@Override public void checkLogin(int userId, String password) { User u = userRepository.findOne(userId); if (u == null || !passwordEncoder.matches(password, u.getPassword())) { throw new UserServiceException("Username or password isn't correct"); } }
@Override public User addUser(User user) { validateUser(user); try { String unencryptedPassword = user.getPassword(); String encryptedPassword = passwordEncoder.encode(unencryptedPassword); user.setPassword(encryptedPassword); return userRepository.save(user); } catch (Exception e) { throw new UserServiceException( String.format("Could not save user with username %s", user.getUsername())); } }