File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -365,6 +365,41 @@ export const defaultConverters: ISchemaConverters = {
365365 type : 'array' ,
366366 uniqueItems : true ,
367367 } ,
368+ [ cv . IS_STRONG_PASSWORD ] : ( meta , options ) => {
369+ const passwordOptions : cv . IsStrongPasswordOptions = meta . constraints [ 0 ]
370+
371+ const requireChars = ( chars : string , amount : number ) : string => {
372+ const charMatcher = chars === '*' ? '' : `*(?:[^${ chars } ]*[${ chars } ])`
373+
374+ return `(?=.${ charMatcher } {${ amount } })`
375+ }
376+
377+ const requirements = (
378+ [
379+ [ '*' , passwordOptions . minLength ] ,
380+ [ 'a-z' , passwordOptions . minLowercase ] ,
381+ [ 'A-Z' , passwordOptions . minUppercase ] ,
382+ [ '0-9' , passwordOptions . minNumbers ] ,
383+ [ options . passwordSymbols , passwordOptions . minSymbols ] ,
384+ ] as const
385+ )
386+ . map ( ( [ chars , amount ] ) => {
387+ if ( ! amount ) {
388+ return
389+ }
390+
391+ return requireChars ( chars , amount )
392+ } )
393+ . filter ( Boolean )
394+ . join ( '' )
395+
396+ const pattern = `^${ requirements } .*$`
397+
398+ return {
399+ type : 'string' ,
400+ pattern,
401+ }
402+ } ,
368403}
369404
370405function getPropType ( target : object , property : string ) {
Original file line number Diff line number Diff line change @@ -40,11 +40,18 @@ export interface IOptions extends ValidatorOptions {
4040 * Defaults to `name`, i.e., class name.
4141 */
4242 schemaNameField : string
43+
44+ /**
45+ * Characters that are considered symbols n passwords.
46+ * Defaults to the symbol character set of `validator.js`.
47+ */
48+ passwordSymbols : string
4349}
4450
4551export const defaultOptions : IOptions = {
4652 additionalConverters : { } ,
4753 classValidatorMetadataStorage : getMetadataStorage ( ) ,
4854 refPointerPrefix : '#/definitions/' ,
4955 schemaNameField : 'name' ,
56+ passwordSymbols : '-#!$@£%^&*()_+|~=`{}\\[\\]:";\'<>?,.\\/ ' ,
5057}
You can’t perform that action at this time.
0 commit comments