mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-25 07:14:00 +08:00
extracted strong password check to a util function
This commit is contained in:
parent
d0b3cc6e96
commit
b26348fcce
2 changed files with 24 additions and 24 deletions
|
@ -540,30 +540,6 @@ async function signUp(): Promise<void> {
|
|||
return;
|
||||
}
|
||||
|
||||
// Force user to use a capital letter, number, special character when setting up an account and changing password
|
||||
if (password.length < 8) {
|
||||
Notifications.add("Password must be at least 8 characters", 0, 3);
|
||||
LoginPage.hidePreloader();
|
||||
LoginPage.enableInputs();
|
||||
LoginPage.updateSignupButton();
|
||||
return;
|
||||
}
|
||||
|
||||
const hasCapital = password.match(/[A-Z]/);
|
||||
const hasNumber = password.match(/[\d]/);
|
||||
const hasSpecial = password.match(/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/);
|
||||
if (!hasCapital || !hasNumber || !hasSpecial) {
|
||||
Notifications.add(
|
||||
"Password must contain at least one capital letter, number, and special character",
|
||||
0,
|
||||
3
|
||||
);
|
||||
LoginPage.hidePreloader();
|
||||
LoginPage.enableInputs();
|
||||
LoginPage.updateSignupButton();
|
||||
return;
|
||||
}
|
||||
|
||||
if (password !== passwordVerify) {
|
||||
Notifications.add("Passwords do not match", 0, 3);
|
||||
LoginPage.hidePreloader();
|
||||
|
@ -572,6 +548,22 @@ async function signUp(): Promise<void> {
|
|||
return;
|
||||
}
|
||||
|
||||
// Force user to use a capital letter, number, special character when setting up an account and changing password
|
||||
if (
|
||||
window.location.hostname !== "localhost" &&
|
||||
!Misc.isPasswordStrong(password)
|
||||
) {
|
||||
Notifications.add(
|
||||
"Password must contain at least one capital letter, number, a special character and at least 8 characters long",
|
||||
0,
|
||||
4
|
||||
);
|
||||
LoginPage.hidePreloader();
|
||||
LoginPage.enableInputs();
|
||||
LoginPage.updateSignupButton();
|
||||
return;
|
||||
}
|
||||
|
||||
authListener();
|
||||
|
||||
let createdAuthUser;
|
||||
|
|
|
@ -1235,3 +1235,11 @@ export function abbreviateNumber(num: number): string {
|
|||
export async function sleep(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
export function isPasswordStrong(password: string): boolean {
|
||||
const hasCapital = !!password.match(/[A-Z]/);
|
||||
const hasNumber = !!password.match(/[\d]/);
|
||||
const hasSpecial = !!password.match(/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/);
|
||||
const isLong = password.length >= 8;
|
||||
return hasCapital && hasNumber && hasSpecial && isLong;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue