diff --git a/src/main/java/com/chat/yourway/annotation/validator/PasswordValidator.java b/src/main/java/com/chat/yourway/annotation/validator/PasswordValidator.java index 4ba1e9f2..3096d422 100644 --- a/src/main/java/com/chat/yourway/annotation/validator/PasswordValidator.java +++ b/src/main/java/com/chat/yourway/annotation/validator/PasswordValidator.java @@ -15,6 +15,10 @@ public class PasswordValidator implements ConstraintValidator;/.:'(),\\[\\]\"].*"); + private static final Pattern PASSWORD_FORBIDEN_CYRILLIC_LETTERS_PATTERN = + Pattern.compile(".*[а-яА-ЯІіЇї].*"); @Override public boolean isValid(String value, ConstraintValidatorContext context) { @@ -35,7 +39,17 @@ public boolean isValid(String value, ConstraintValidatorContext context) { .buildConstraintViolationWithTemplate("The password must not be longer than 12 characters.") .addConstraintViolation(); return false; - } else if (!PASSWORD_SPECIAL_SYMBOLS_PATTERN.matcher(value).matches()) { + } else if (PASSWORD_FORBIDEN_SYMBOLS_PATTERN.matcher(value).matches()) { + context + .buildConstraintViolationWithTemplate("Password should not include symbols [< > ; / . : ' [ ] ( ) , ]") + .addConstraintViolation(); + return false; + } else if (PASSWORD_FORBIDEN_CYRILLIC_LETTERS_PATTERN.matcher(value).matches()) { + context + .buildConstraintViolationWithTemplate("Password should not include cyrillic letters") + .addConstraintViolation(); + return false; + }else if (!PASSWORD_SPECIAL_SYMBOLS_PATTERN.matcher(value).matches()) { context .buildConstraintViolationWithTemplate("Password must include at least 1 special symbol: [! @ # $ % ^ & * _ - + = ~ ?]") .addConstraintViolation(); diff --git a/src/test/java/com/chat/yourway/unit/annotation/validator/PasswordValidationValidatorTest.java b/src/test/java/com/chat/yourway/unit/annotation/validator/PasswordValidationValidatorTest.java index b392935e..b5800f2d 100644 --- a/src/test/java/com/chat/yourway/unit/annotation/validator/PasswordValidationValidatorTest.java +++ b/src/test/java/com/chat/yourway/unit/annotation/validator/PasswordValidationValidatorTest.java @@ -142,7 +142,24 @@ public void shouldFailValidator_whenUserInputPasswordWithSpace() { @Test public void shouldFailValidator_whenUserInputPasswordWithForbiddenSymbols() { // Given - var password = "