/** * Checks the password quality of a new password. Password must have at least n characters and at minimum one letter * and one non-letter character. * * @return null if password quality is OK, otherwise the i18n message key of the password check failure. */ @Override public List<I18nKeyAndParams> checkPasswordQuality(final String password) { return this.validate(password, null, false); }
private List<I18nKeyAndParams> validate(final String newPassword, final String oldPassword, final boolean checkOldPassword) { final List<I18nKeyAndParams> result = new ArrayList<>(); // check min length final int minPasswordLength = configurationService.getMinPasswordLength(); if (newPassword == null || newPassword.length() < minPasswordLength) { result.add(new I18nKeyAndParams(MESSAGE_KEY_PASSWORD_MIN_LENGTH_ERROR, configurationService.getMinPasswordLength())); if (newPassword == null) { return result; } } // check for character and none character checkForCharsInPassword(newPassword, result); // stop here if only the new password is validated if (checkOldPassword == false) { return result; } // compare old and new password if (configurationService.getFlagCheckPasswordChange() && StringUtils.equals(oldPassword, newPassword)) { result.add(new I18nKeyAndParams(MESSAGE_KEY_PASSWORD_OLD_EQ_NEW_ERROR)); } return result; }
/** * Checks the password quality of a new password change is required. Password must have at least n characters and at minimum one letter * and one non-letter character. * * @param newPassword * @return null if password quality is OK, otherwise the i18n message key of the password check failure. */ @Override public List<I18nKeyAndParams> checkPasswordQuality(final String oldPassword, final String newPassword) { return validate(newPassword, oldPassword, true); }