Merged in fix/SW-3111-mismatch-password-rules (pull request #2482)

fix(SW-3111): Added test for passwordValidator and updated pw validation

* fix(SW-3111): Added test for passwordValidator and updated pw validation

* fix: make sure regex is matching Curity

* Added error message to input field and changed message

* Fixed text


Approved-by: Christian Andolf
This commit is contained in:
Tobias Johansson
2025-07-01 05:51:31 +00:00
committed by Linus Flood
parent f207cf6601
commit f0701d6e20
3 changed files with 113 additions and 4 deletions

View File

@@ -7,11 +7,11 @@ export const passwordValidators = {
message: "10 to 40 characters",
},
hasUppercase: {
matcher: (password: string) => /[A-Z]/.test(password),
matcher: (password: string) => /[A-ZÅÄÖÆØÜ]/.test(password),
message: "1 uppercase letter",
},
hasLowercase: {
matcher: (password: string) => /[a-z]/.test(password),
matcher: (password: string) => /[a-zåäöæøüß]/.test(password),
message: "1 lowercase letter",
},
hasNumber: {
@@ -19,16 +19,23 @@ export const passwordValidators = {
message: "1 number",
},
hasSpecialChar: {
matcher: (password: string) =>
/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+/.test(password),
matcher: (password: string) => /[&!?()@#$%^+=_\*\-]+/.test(password),
message: "1 special character",
},
allowedCharacters: {
matcher: (password: string) =>
/^[A-Za-zåäöæøüßÅÄÖÆØÜ0-9&!?()@#$%^+=_\*\-]+$/.test(password),
message: "Only allowed characters",
},
}
export const passwordValidator = (msg = "Required field") =>
z
.string()
.min(1, msg)
.refine(passwordValidators.allowedCharacters.matcher, {
message: passwordValidators.allowedCharacters.message,
})
.refine(passwordValidators.length.matcher, {
message: passwordValidators.length.message,
})