File tree Expand file tree Collapse file tree 4 files changed +29
-11
lines changed Expand file tree Collapse file tree 4 files changed +29
-11
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 ( {
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import LoadingScreen from "@/components/common/loading-screen";
24
24
import { useAuth } from "@/app/auth/auth-context" ;
25
25
import { cn } from "@/lib/utils" ;
26
26
import { User , UserSchema } from "@/lib/schemas/user-schema" ;
27
+ import { isPasswordComplex } from "@/lib/password" ;
27
28
import { userServiceUri } from "@/lib/api-uri" ;
28
29
29
30
const fetcher = async ( url : string ) : Promise < User > => {
@@ -300,16 +301,6 @@ export default function UserSettings({ userId }: { userId: string }) {
300
301
}
301
302
} , [ newPassword , confirmPassword ] ) ;
302
303
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
-
313
304
if ( isLoading ) {
314
305
return < LoadingScreen /> ;
315
306
}
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments