Hola coders espero que esten bien les quiero hacer una consulta tengo que hacer este endpoint "api/compliance/password/{password}" y el password debe cumplir con ciertos requisitos Complexity = at least 8 characters at least one digit at least one special character (!,#,$,%,&,@) at least one uppercase letter
les dejo el metodo que he creado para hacer esas validaciones
public Compliance validatePassword(String password) {
boolean isPasswordValid = true;
final String MUST_CONTAIN_ONE_UPPERCASE_LETTER = "^.*[A-Z]+.*$";
final String MUST_CONTAIN_ONE_DIGIT = "^.*[0-9]+.*$";
final String MUST_CONTAIN_ONE_SPECIAL_CHARACTER = "^.*[!&$%@]+.*$";
List<String> reasonsForInvalidPassword = new ArrayList<>();
if (password.length() < 8) {
reasonsForInvalidPassword.add("Password must be at least 8 character long");
isPasswordValid = false;
}
if (!password.matches(MUST_CONTAIN_ONE_UPPERCASE_LETTER)) {
reasonsForInvalidPassword.add("Password must be at least one upper case letter");
isPasswordValid = false;
}
if (!password.matches(MUST_CONTAIN_ONE_DIGIT)) {
reasonsForInvalidPassword.add("Password must be at least one digit");
isPasswordValid = false;
}
if (!password.matches(MUST_CONTAIN_ONE_SPECIAL_CHARACTER)) {
reasonsForInvalidPassword.add("Password must be at least one special character");
isPasswordValid = false;
}
String reason = reasonsForInvalidPassword.stream().collect(Collectors.joining(", "));
return new Compliance(isPasswordValid, reason);
}
tambie les dejo mi metodo getmapping
@GetMapping(path = "/compliance/password/{password}")
public ResponseEntity<Compliance> getPassword(@PathVariable("password") String password) {
Compliance compliance = iComplianceService.validatePassword(password);
return ResponseEntity.status(HttpStatus.OK)
.body(compliance);
}
el problema es que acepta todos caracteres especiales exepto % me sale un lindo error en postman
<!doctype html><html lang="en"><head><title>HTTP Status 400 – Bad Request</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 400 – Bad Request</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> Invalid URI: End of file (EOF)</p><p><b>Description</b> The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).</p><hr class="line" /><h3>Apache Tomcat/9.0.45</h3></body></html>
les agradezco por su ayuda