File tree Expand file tree Collapse file tree
apps/web/src/features/admin/pages Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11/* eslint-disable perfectionist/sort-objects */
22
3+ import { estimatePasswordStrength } from '@douglasneuroinformatics/libpasswd' ;
34import { Form , Heading } from '@douglasneuroinformatics/libui/components' ;
45import { useTranslation } from '@douglasneuroinformatics/libui/hooks' ;
56import { $BasePermissionLevel , $CreateUserData , type CreateUserData } from '@opendatacapture/schemas/user' ;
@@ -44,6 +45,9 @@ export const CreateUserPage = () => {
4445 variant : 'input'
4546 } ,
4647 password : {
48+ calculateStrength : ( password ) => {
49+ return estimatePasswordStrength ( password ) . score ;
50+ } ,
4751 kind : 'string' ,
4852 label : t ( 'common.password' ) ,
4953 variant : 'password'
@@ -125,6 +129,15 @@ export const CreateUserPage = () => {
125129 confirmPassword : z . string ( ) . min ( 1 )
126130 } )
127131 . superRefine ( ( arg , ctx ) => {
132+ if ( ! estimatePasswordStrength ( arg . password ) . success ) {
133+ ctx . addIssue ( {
134+ code : z . ZodIssueCode . custom ,
135+ fatal : true ,
136+ message : t ( 'common.insufficientPasswordStrength' ) ,
137+ path : [ 'password' ]
138+ } ) ;
139+ return z . NEVER ;
140+ }
128141 if ( arg . confirmPassword !== arg . password ) {
129142 ctx . addIssue ( {
130143 code : z . ZodIssueCode . custom ,
You can’t perform that action at this time.
0 commit comments