Skip to content

Commit 677118e

Browse files
committed
Extract out isPasswordComplex
1 parent 3259ce0 commit 677118e

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

frontend/components/user-settings/user-settings.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import LoadingScreen from "@/components/common/loading-screen";
2424
import { useAuth } from "@/app/auth/auth-context";
2525
import { cn } from "@/lib/utils";
2626
import { User, UserSchema } from "@/lib/schemas/user-schema";
27+
import { isPasswordComplex } from "@/lib/password";
2728
import { userServiceUri } from "@/lib/api-uri";
2829

2930
const fetcher = async (url: string): Promise<User> => {
@@ -300,16 +301,6 @@ export default function UserSettings({ userId }: { userId: string }) {
300301
}
301302
}, [newPassword, confirmPassword]);
302303

303-
const isPasswordComplex = (password: string) => {
304-
const minLength = 8;
305-
const hasUpperCase = /[A-Z]/.test(password);
306-
const hasSpecialChar = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+/.test(
307-
password
308-
);
309-
310-
return password.length >= minLength && hasUpperCase && hasSpecialChar;
311-
};
312-
313304
if (isLoading) {
314305
return <LoadingScreen />;
315306
}

frontend/lib/password.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export const isPasswordComplex = (password: string) => {
2+
const minLength = 8;
3+
const hasUpperCase = /[A-Z]/.test(password);
4+
const hasSpecialChar = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+/.test(
5+
password
6+
);
7+
8+
return password.length >= minLength && hasUpperCase && hasSpecialChar;
9+
};

0 commit comments

Comments
 (0)