File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 3
3
import { useState } from "react" ;
4
4
import { useRouter } from "next/navigation" ;
5
5
import { resetPassword } from "@/lib/reset-password" ;
6
+ import { isPasswordComplex } from "@/lib/password" ;
6
7
import { useToast } from "@/components/hooks/use-toast" ;
7
8
8
9
import { Button } from "@/components/ui/button" ;
@@ -24,14 +25,22 @@ export function ResetPasswordForm({ token }: { token: string }) {
24
25
25
26
const handleSubmit = async ( event : React . FormEvent ) => {
26
27
event . preventDefault ( ) ;
27
- // TODO: Add validation for password
28
28
if ( password !== passwordConfirmation ) {
29
29
toast ( {
30
30
title : "Password Mismatch" ,
31
31
description : "The passwords you entered do not match" ,
32
32
} ) ;
33
33
return ;
34
34
}
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
+
35
44
const res = await resetPassword ( token , password ) ;
36
45
if ( ! res . ok ) {
37
46
toast ( {
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { useState } from "react";
5
5
import { useRouter } from "next/navigation" ;
6
6
import { toast } from "@/components/hooks/use-toast" ;
7
7
import { signUp } from "@/lib/signup" ;
8
+ import { isPasswordComplex } from "@/lib/password" ;
8
9
9
10
import { Button } from "@/components/ui/button" ;
10
11
import {
@@ -34,6 +35,14 @@ export function SignUpForm() {
34
35
} ) ;
35
36
return ;
36
37
}
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
+ }
37
46
const res = await signUp ( username , email , password ) ;
38
47
if ( ! res . ok ) {
39
48
toast ( {
You can’t perform that action at this time.
0 commit comments