Pure JS Cracklib-inspired library for Node.
MIT License
Pure JS Cracklib-inspired library for Node.
npm i cracklibjs
import cracklib from 'cracklibjs'
// if you're using `require`, you'll need to `require('cracklibjs').default`
const pw = process.argv[2] // or something
// Init with options. The wordlist is parsed here, so future calls
// don't have to do all that work again.
// `check: (word: string) => PasswordValidationError | string (word)`
const check = cracklib() // cracklib(options)
// The `options` param is optional.
// type Options = {
// dict: string = '/usr/share/dict/words'; path to dictionary file
// minLength: number = 8; minimum password length
// loose: bool = false; see below for loose vs strict
// }
const validate = (pw) => {
try {
return check(pw)
} catch (e) {
return e.message // example: 'Password is too short'
}
}
The loose
option, when true, disables:
cracklib
isn't a vanilla JS solution, has externalcat(1)