Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat 169 bugfix password field accepted cyrillic and prohibited symbols #52

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,24 @@ public void shouldFailValidator_whenUserInputPasswordWithSpace() {
@Test
public void shouldFailValidator_whenUserInputPasswordWithForbiddenSymbols() {
// Given
var password = "<Password!";
var password1 = "<Password!";
var password2 = "hjj;^33N";

// When
var isValid1 = passwordValidator.isValid(password1, context);
var isValid2 = passwordValidator.isValid(password2, context);

// Then
assertFalse(isValid1);
assertFalse(isValid2);
}

@DisplayName(
"PasswordValidator should fail validator when user input password with cyrillic letters")
@Test
public void shouldFailValidator_whenUserInputPasswordWithCyrillicLetters() {
// Given
var password = "Ася_77";

// When
var isValid = passwordValidator.isValid(password, context);
Expand Down
Loading