use of org.craftercms.studio.api.v1.exception.security.PasswordDoesNotMatchException in project studio by craftercms.
the class UserServiceInternalImpl method changePassword.
@RetryingOperation
@Override
public boolean changePassword(String username, String current, String newPassword) throws PasswordDoesNotMatchException, UserExternallyManagedException, ServiceLayerException {
Map<String, Object> params = new HashMap<String, Object>();
params.put(USER_ID, -1);
params.put(USERNAME, username);
try {
User user = userDao.getUserByIdOrUsername(params);
if (user.isExternallyManaged()) {
throw new UserExternallyManagedException();
} else {
if (CryptoUtils.matchPassword(user.getPassword(), current)) {
if (verifyPasswordRequirements(newPassword)) {
String hashedPassword = CryptoUtils.hashPassword(newPassword);
params = new HashMap<>();
params.put(USERNAME, username);
params.put(PASSWORD, hashedPassword);
userDao.setUserPassword(params);
return true;
} else {
throw new PasswordRequirementsFailedException();
}
} else {
throw new PasswordDoesNotMatchException();
}
}
} catch (RuntimeException e) {
throw new ServiceLayerException("Unknown database error", e);
}
}
Aggregations