Enforce rules on passwords.
npm install --save password-rules
Or download password-rules.js
for a browser.
Options:
minimumLength
: default 8maximumLength
: default InfinityrequireCapital
: default truerequireLower
: default truerequireNumber
: default truerequireSpecial
: default false
Returns false
if there are no issues. Otherwise, returns an object like
{ sentence: 'Password must be at least 8 letters long, contain a capital letter, contain a number, and contain a special character.',
issues:
[ { reason: 'minimumLength',
message: 'Password must be at least 8 letters long',
part: 'be at least 8 letters long' },
{ reason: 'requireCapital',
message: 'Password must contain a capital letter',
part: 'contain a capital letter' },
{ reason: 'requireNumber',
message: 'Password must contain a number',
part: 'contain a number' },
{ reason: 'requireSpecial',
message: 'Password must contain a special character',
part: 'contain a special character'} ] }