Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions server/src/main/java/com/cloud/user/PasswordPolicyImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public class PasswordPolicyImpl implements PasswordPolicy, Configurable {
private Logger logger = Logger.getLogger(PasswordPolicyImpl.class);

public void verifyIfPasswordCompliesWithPasswordPolicies(String password, String username, Long domainId) {
if (StringUtils.isEmpty(password)) {
logger.warn(String.format("User [%s] has an empty password, skipping password policy checks. " +
"If this is not a LDAP user, there is something wrong.", username));
return;
}

int numberOfSpecialCharactersInPassword = 0;
int numberOfUppercaseLettersInPassword = 0;
int numberOfLowercaseLettersInPassword = 0;
Expand Down Expand Up @@ -188,12 +194,12 @@ protected void validateIfPasswordMatchesRegex(String password, String username,
logger.trace(String.format("Validating if the new password for user [%s] matches regex [%s] defined in the configuration [%s].",
username, passwordPolicyRegex, PasswordPolicyRegex.key()));

if (passwordPolicyRegex == null){
logger.trace(String.format("Regex is null; therefore, we will not validate if the new password matches with regex for user [%s].", username));
if (StringUtils.isEmpty(passwordPolicyRegex)) {
logger.trace(String.format("Regex is empty; therefore, we will not validate if the new password matches with regex for user [%s].", username));
return;
}

if (!password.matches(passwordPolicyRegex)){
if (!password.matches(passwordPolicyRegex)) {
Comment thread
JoaoJandre marked this conversation as resolved.
Resolved
logger.error(String.format("User [%s] informed a new password that does not match with regex [%s]. Refusing the user's new password.", username, passwordPolicyRegex));
throw new InvalidParameterValueException("User password does not match with password policy regex.");
}
Expand Down