|
|
@ -1,8 +1,18 @@ |
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
public class PasswordValidator { |
|
|
|
int minLength = 6; |
|
|
|
boolean requireUppercase = true; |
|
|
|
|
|
|
|
private final Pattern uppercasePattern = Pattern.compile("^(?=.*[A-Z]).+$"); |
|
|
|
|
|
|
|
public boolean validate(String password) { |
|
|
|
return password.length() >= minLength; |
|
|
|
if (password.length() < minLength) { |
|
|
|
return false; |
|
|
|
} else if (requireUppercase && !uppercasePattern.matcher(password).matches()) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
public int getMinLength() { |
|
|
@ -12,4 +22,12 @@ public class PasswordValidator { |
|
|
|
public void setMinLength(int minLength) { |
|
|
|
this.minLength = minLength; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean isRequireUppercase() { |
|
|
|
return requireUppercase; |
|
|
|
} |
|
|
|
|
|
|
|
public void setRequireUppercase(boolean requireUppercase) { |
|
|
|
this.requireUppercase = requireUppercase; |
|
|
|
} |
|
|
|
} |