Joi Password Complexity
Creates a Joi object that validates password complexity.
Requirements
- Joi v16 or higher
- Nodejs 10 or higher
Installation
npm install joi-password-complexity
Examples
No options specified
const passwordComplexity = require('joi-password-complexity');
passwordComplexity().validate('aPassword123!');
When no options are specified, the following are used:
{
min: 8,
max: 26,
lowerCase: 1,
upperCase: 1,
numeric: 1,
symbol: 1,
requirementCount: 4,
}
Options specified
const passwordComplexity = require('joi-password-complexity');
const complexityOptions = {
min: 10,
max: 30,
lowerCase: 1,
upperCase: 1,
numeric: 1,
symbol: 1,
requirementCount: 2,
}
passwordComplexity(complexityOptions).validate('aPassword123!');
Error Label (optional) Specified
const passwordComplexity = require('joi-password-complexity');
passwordComplexity(undefined, 'Password').validate('aPassword123!');
The resulting error message:
'Password should be at least 8 characters long'
License
MIT
v4.2.0
Note: As joi changes over time, this module will exclusively track sideway/joi.
Peer Dependency
Peer dependency on @hapi/joi has been removed. You will receive a runtime error instead if joi is not peer-installed.
In the future when we exclusively track sideway/joi, the peer dependency will be restored.