Skip to content

Commit

Permalink
bugfix: added forbidden symbols and cyrillic letters to password vali…
Browse files Browse the repository at this point in the history
…dation
  • Loading branch information
Troha7 committed Jan 6, 2024
1 parent 9927f5f commit 6d8468f
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public class PasswordValidator implements ConstraintValidator<PasswordValidation
Pattern.compile(".*[!@#$%^&*_\\-+=~?].*");
private static final Pattern PASSWORD_UPPER_CASE_PATTERN = Pattern.compile(".*[A-Z].*");
private static final Pattern PASSWORD_DIGIT_PATTERN = Pattern.compile(".*\\d.*");
private static final Pattern PASSWORD_FORBIDEN_SYMBOLS_PATTERN =
Pattern.compile(".*[<>;/.:'(),\\[\\]\"].*");
private static final Pattern PASSWORD_FORBIDEN_CYRILLIC_LETTERS_PATTERN =
Pattern.compile(".*[а-яА-ЯІіЇї].*");

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
Expand All @@ -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();
Expand Down

0 comments on commit 6d8468f

Please sign in to comment.