Skip to content

Commit 800f168

Browse files
committed
Add password complexity check
1 parent 677118e commit 800f168

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

frontend/components/auth/reset-password-form.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { useState } from "react";
44
import { useRouter } from "next/navigation";
55
import { resetPassword } from "@/lib/reset-password";
6+
import { isPasswordComplex } from "@/lib/password";
67
import { useToast } from "@/components/hooks/use-toast";
78

89
import { Button } from "@/components/ui/button";
@@ -24,14 +25,22 @@ export function ResetPasswordForm({ token }: { token: string }) {
2425

2526
const handleSubmit = async (event: React.FormEvent) => {
2627
event.preventDefault();
27-
// TODO: Add validation for password
2828
if (password !== passwordConfirmation) {
2929
toast({
3030
title: "Password Mismatch",
3131
description: "The passwords you entered do not match",
3232
});
3333
return;
3434
}
35+
if (!isPasswordComplex(passwordConfirmation)) {
36+
toast({
37+
title: "Weak Password",
38+
description:
39+
"Password must be at least 8 characters long, include 1 uppercase letter and 1 special character.",
40+
});
41+
return;
42+
}
43+
3544
const res = await resetPassword(token, password);
3645
if (!res.ok) {
3746
toast({

frontend/components/auth/sign-up-form.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useState } from "react";
55
import { useRouter } from "next/navigation";
66
import { toast } from "@/components/hooks/use-toast";
77
import { signUp } from "@/lib/signup";
8+
import { isPasswordComplex } from "@/lib/password";
89

910
import { Button } from "@/components/ui/button";
1011
import {
@@ -34,6 +35,14 @@ export function SignUpForm() {
3435
});
3536
return;
3637
}
38+
if (!isPasswordComplex(passwordConfirmation)) {
39+
toast({
40+
title: "Weak Password",
41+
description:
42+
"Password must be at least 8 characters long, include 1 uppercase letter and 1 special character.",
43+
});
44+
return;
45+
}
3746
const res = await signUp(username, email, password);
3847
if (!res.ok) {
3948
toast({

0 commit comments

Comments
 (0)