check-password-complexity: A simple javascript utility to check password strength and complexity.
npm install check-password-complexity
or
yarn add check-password-complexity
import { checkPasswordComplexity } from "check-password-complexity";
// OR
const { checkPasswordComplexity } = require("check-password-complexity");
console.log(checkPasswordComplexity("abcdefgh").value); // tooWeak
checkPasswordComplexity("abcdefg8").value; // weak
checkPasswordComplexity("abcdefgh9").value; // medium
checkPasswordComplexity("abcdefgh9F=").value; // strong
Property | Type | Description |
---|---|---|
value | tooWeak, weak, medium, strong |
Too Weak, Weak, Medium or Strong |
checkedRules | (minLength, lowercase, uppercase, number, specialCharacter)[] |
List of all checked values |
length | number |
Length of the password |
checkPasswordComplexity("abcdefg");
/**
checkedRules: ['lowercase']
length: 7
value: "tooWeak"
*/
checkPasswordComplexity("abcdefg8");
/**
checkedRules: ['lowercase', 'number']
length: 8
value: "weak"
*/
checkPasswordComplexity("abcdefgh9");
/**
checkedRules: ['minLength', 'lowercase', 'number']
length: 9
value: "medium"
*/
checkPasswordComplexity("abcdefgh9F=");
/**
checkedRules: ['minLength', 'lowercase', 'uppercase', 'number', 'specialCharacter']
length: 11
value: "strong"
*/
property | type | Default value | Description |
---|---|---|---|
minLength | number |
8 | Number of minimum character |
allowedSpecialChar | string |
!@#$%^&*(),.?":{}<>\[\]\\/`~;'_+=- | regex for the special character to use |
checkPasswordComplexity("abcdefg", { minLength: 6 });
/**
checkedRules: ['minLength', 'lowercase']
length: 7
value: "weak"
*/
// example: "." is the special character to be allowed
checkPasswordComplexity("abcdefg.", { allowedSpecialChar: "." });
/**
checkedRules: ['lowercase', 'specialCharacter']
length: 8
value: "weak"
*/
Contributions & pull requests are welcome! Get started here.
If you find this project useful, don't forget to give a ★ on GitHub