You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
837 B
33 lines
837 B
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) {
|
|
if (password.length() < minLength) {
|
|
return false;
|
|
} else if (requireUppercase && !uppercasePattern.matcher(password).matches()) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public int getMinLength() {
|
|
return minLength;
|
|
}
|
|
|
|
public void setMinLength(int minLength) {
|
|
this.minLength = minLength;
|
|
}
|
|
|
|
public boolean isRequireUppercase() {
|
|
return requireUppercase;
|
|
}
|
|
|
|
public void setRequireUppercase(boolean requireUppercase) {
|
|
this.requireUppercase = requireUppercase;
|
|
}
|
|
}
|