Added password criterion support for multiple languages and emojis

This commit is contained in:
Joel Biddle
2023-08-23 01:27:30 +10:00
parent e5c87442e5
commit b2888272f2
8 changed files with 23 additions and 15 deletions
@@ -46,7 +46,7 @@ const passwordCheck = async ({
}
// upperCase
if (!/[A-Z]/.test(password)) {
if (!/[A-Z\u0041-\u005A\u00C0-\u00D6\u00D8-\u00DE]/.test(password)) {
setPasswordErrorUpperCase(true);
errorCheck = true;
} else {
@@ -54,7 +54,7 @@ const passwordCheck = async ({
}
// lowerCase
if (!/[a-z]/.test(password)) {
if (!/[a-z\u0061-\u007A\u00DF-\u00F6\u00F8-\u00FF]/.test(password)) {
setPasswordErrorLowerCase(true);
errorCheck = true;
} else {
@@ -82,7 +82,11 @@ const passwordCheck = async ({
}
// repeatedChar
if (/([A-Za-z0-9])\1\1\1/.test(password)) {
if (
/([!@#$%^&*(),.?":{}|<>0-9A-Za-z\u3040-\u309F\u30A0-\u30FF\u4E00-\u9FFF\u0600-\u06FF\u0400-\u04FF\u0500-\u052F\u2DE0-\u2DFF\uA640-\uA69F\u05B0-\u05FF\u0980-\u09FF\u1F00-\u1FFF\u0130\u015E\u011E\u00D6\u00C7\u00FC\u00FB\u00F6\u00EB\u00E7\u00C7\u003a-\u003f\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF\p{Emoji}])\1\1/.test(
password
)
) {
setPasswordErrorRepeatedChar(true);
errorCheck = true;
} else {
@@ -49,12 +49,12 @@ const checkPassword = async ({ password, setErrors }: CheckPasswordParams): Prom
}
// upperCase
if (!/[A-Z]/.test(password)) {
if (!/[A-Z\u0041-\u005A\u00C0-\u00D6\u00D8-\u00DE]/.test(password)) {
errors.upperCase = "at least 1 uppercase character (A-Z)";
}
// lowerCase
if (!/[a-z]/.test(password)) {
if (!/[a-z\u0061-\u007A\u00DF-\u00F6\u00F8-\u00FF]/.test(password)) {
errors.lowerCase = "at least 1 lowercase character (a-z)";
}
@@ -70,18 +70,22 @@ const checkPassword = async ({ password, setErrors }: CheckPasswordParams): Prom
)
) {
errors.specialChar =
'at least 1 special character (!@#$%^&*(),.?":{}|<>), Japanese, Korean, Arabic, Cyrillic, Greek, Devanagari, Turkish, or an emoji';
'at least 1 special character from !@#$%^&*(),.?":{}|<>, Japanese, Korean, Arabic, Cyrillic, Greek, Devanagari, Turkish, or an emoji';
}
// repeatedChar
if (/([A-Za-z0-9])\1\1\1/.test(password)) {
errors.repeatedChar = "No 3 repeat, consecutive characters";
if (
/([!@#$%^&*(),.?":{}|<>0-9A-Za-z\u3040-\u309F\u30A0-\u30FF\u4E00-\u9FFF\u0600-\u06FF\u0400-\u04FF\u0500-\u052F\u2DE0-\u2DFF\uA640-\uA69F\u05B0-\u05FF\u0980-\u09FF\u1F00-\u1FFF\u0130\u015E\u011E\u00D6\u00C7\u00FC\u00FB\u00F6\u00EB\u00E7\u00C7\u003a-\u003f\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF\p{Emoji}])\1\1/.test(
password
)
) {
errors.repeatedChar = "At most 2 repeated, consecutive characters";
}
// breachedPassword
if (await checkIsPasswordBreached(password)) {
errors.isBreachedPassword =
"The provided password is in a list of passwords commonly used on other websites. Please try again with a stronger password.";
"The new password is in a list of passwords commonly used on other websites. Please try again with a stronger password.";
}
setErrors(errors);