@@ -45,27 +45,34 @@ export function SignUpModal({
45
45
const [ resendMessage , setResendMessage ] = useState < string | null > ( null ) ;
46
46
const [ passwordConfirm , setPasswordConfirm ] = useState ( '' ) ;
47
47
const [ passwordError , setPasswordError ] = useState < string | null > ( null ) ;
48
- const [ passwordStrength , setPasswordStrength ] = useState < 'weak' | 'medium' | 'strong' | null > ( null ) ;
48
+ const [ passwordStrength , setPasswordStrength ] = useState <
49
+ 'weak' | 'medium' | 'strong' | null
50
+ > ( null ) ;
49
51
50
52
const validatePassword = ( value : string ) => {
51
53
// Reset errors
52
54
setPasswordError ( null ) ;
53
-
55
+
54
56
// Check minimum length
55
57
if ( value . length < 6 ) {
56
58
setPasswordError ( 'Password must be at least 6 characters long' ) ;
57
59
setPasswordStrength ( 'weak' ) ;
58
60
return false ;
59
61
}
60
-
62
+
61
63
// Check for complexity
62
64
const hasUppercase = / [ A - Z ] / . test ( value ) ;
63
65
const hasLowercase = / [ a - z ] / . test ( value ) ;
64
66
const hasNumbers = / \d / . test ( value ) ;
65
67
const hasSpecialChar = / [ ! @ # $ % ^ & * ( ) _ + \- = [ \] { } ; ' : " \\ | , . < > / ? ] / . test ( value ) ;
66
-
67
- const strengthScore = [ hasUppercase , hasLowercase , hasNumbers , hasSpecialChar ] . filter ( Boolean ) . length ;
68
-
68
+
69
+ const strengthScore = [
70
+ hasUppercase ,
71
+ hasLowercase ,
72
+ hasNumbers ,
73
+ hasSpecialChar ,
74
+ ] . filter ( Boolean ) . length ;
75
+
69
76
if ( strengthScore < 2 ) {
70
77
setPasswordStrength ( 'weak' ) ;
71
78
setPasswordError ( 'Password is too weak' ) ;
@@ -349,52 +356,74 @@ export function SignUpModal({
349
356
className = { `w-full ${ passwordError ? 'border-red-500' : '' } ` }
350
357
/>
351
358
{ password && (
352
- < div className = "mt-2 space-y-2" >
353
- < div className = "flex items-center gap-2" >
354
- < div className = "text-sm" > Password strength:</ div >
355
- < div className = "flex h-2 w-full max-w-[100px] overflow-hidden rounded-full bg-gray-200 dark:bg-gray-700" >
356
- < div
357
- className = { `h-full ${
358
- passwordStrength === 'weak'
359
- ? 'w-1/3 bg-red-500'
360
- : passwordStrength === 'medium'
361
- ? 'w-2/3 bg-yellow-500'
362
- : 'w-full bg-green-500'
363
- } `}
364
- />
359
+ < div className = "mt-2 space-y-2" >
360
+ < div className = "flex items-center gap-2" >
361
+ < div className = "text-sm" > Password strength:</ div >
362
+ < div className = "flex h-2 w-full max-w-[100px] overflow-hidden rounded-full bg-gray-200 dark:bg-gray-700" >
363
+ < div
364
+ className = { `h-full ${
365
+ passwordStrength === 'weak'
366
+ ? 'w-1/3 bg-red-500'
367
+ : passwordStrength === 'medium'
368
+ ? 'w-2/3 bg-yellow-500'
369
+ : 'w-full bg-green-500'
370
+ } `}
371
+ />
372
+ </ div >
373
+ < div className = "text-sm" >
374
+ { passwordStrength === 'weak'
375
+ ? 'Weak'
376
+ : passwordStrength === 'medium'
377
+ ? 'Medium'
378
+ : 'Strong' }
379
+ </ div >
365
380
</ div >
366
- < div className = "text-sm" >
367
- { passwordStrength === 'weak'
368
- ? 'Weak'
369
- : passwordStrength === 'medium'
370
- ? 'Medium'
371
- : 'Strong' }
381
+
382
+ < div className = "text-xs text-gray-500 dark:text-gray-400" >
383
+ Password must:
384
+ < ul className = "list-disc pl-5 mt-1 space-y-1" >
385
+ < li
386
+ className = {
387
+ password . length >= 6 ? 'text-green-500' : ''
388
+ }
389
+ >
390
+ Be at least 6 characters long
391
+ </ li >
392
+ < li
393
+ className = {
394
+ / [ A - Z ] / . test ( password ) ? 'text-green-500' : ''
395
+ }
396
+ >
397
+ Include at least one uppercase letter
398
+ </ li >
399
+ < li
400
+ className = {
401
+ / \d / . test ( password ) ? 'text-green-500' : ''
402
+ }
403
+ >
404
+ Include at least one number
405
+ </ li >
406
+ < li
407
+ className = {
408
+ / [ ! @ # $ % ^ & * ( ) _ + \- = [ \] { } ; ' : " \\ | , . < > / ? ] / . test (
409
+ password
410
+ )
411
+ ? 'text-green-500'
412
+ : ''
413
+ }
414
+ >
415
+ Include at least one special character
416
+ </ li >
417
+ </ ul >
372
418
</ div >
373
419
</ div >
374
-
375
- < div className = "text-xs text-gray-500 dark:text-gray-400" >
376
- Password must:
377
- < ul className = "list-disc pl-5 mt-1 space-y-1" >
378
- < li className = { password . length >= 6 ? 'text-green-500' : '' } >
379
- Be at least 6 characters long
380
- </ li >
381
- < li className = { / [ A - Z ] / . test ( password ) ? 'text-green-500' : '' } >
382
- Include at least one uppercase letter
383
- </ li >
384
- < li className = { / \d / . test ( password ) ? 'text-green-500' : '' } >
385
- Include at least one number
386
- </ li >
387
- < li className = { / [ ! @ # $ % ^ & * ( ) _ + \- = [ \] { } ; ' : " \\ | , . < > / ? ] / . test ( password ) ? 'text-green-500' : '' } >
388
- Include at least one special character
389
- </ li >
390
- </ ul >
391
- </ div >
392
- </ div >
393
- ) }
420
+ ) }
394
421
395
- { passwordError && (
396
- < div className = "text-red-500 text-xs mt-1" > { passwordError } </ div >
397
- ) }
422
+ { passwordError && (
423
+ < div className = "text-red-500 text-xs mt-1" >
424
+ { passwordError }
425
+ </ div >
426
+ ) }
398
427
</ div >
399
428
400
429
< div className = "space-y-1" >
0 commit comments