@Override public void registerUser(User user, String unencryptedPassword) { user.setPassword(createHash(unencryptedPassword)); try { user.setId(userManager.addUser(user)); } catch (Exception e) { throw new ManagerDataAccessException("Error while registering user", e); } }
@Override public void changePassword(User user, String password, String newUnencryptedPassword) { if (authenticate(user, password)) { user.setPassword(createHash(newUnencryptedPassword)); try { userManager.updateUser(user); } catch (Exception e) { throw new ManagerDataAccessException("Error while rtrieving users", e); } } }
@Override public boolean isAdmin(User u) { return findUserById(u.getId()).getRole() == UserRole.ADMIN; }
@Override public boolean authenticate(User user, String password) { return validatePassword(password, user.getPassword()); }