Skip to content

tiavina-mika/check-password-complexity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 Cannot retrieve latest commit at this time.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

check-password-complexity

check-password-complexity: A simple javascript utility to check password strength and complexity.

Demo

Try it yourself in this CodeSandbox demo Or this Live demo

Installation

npm  install  check-password-complexity

or

yarn  add  check-password-complexity

Get started

Simple usage

import { checkPasswordComplexity } from "check-password-complexity";

// OR

const { checkPasswordComplexity } require("check-password-complexity");

console.log(checkPasswordComplexity("abcdefgh").value); // tooWeak

console.log(checkPasswordComplexity("abcdefg8").value); // weak

console.log(checkPasswordComplexity("abcdefgh9").value); // medium

console.log(checkPasswordComplexity("abcdefgh9F=").value); // strong

Result

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

  console.log(checkPasswordComplexity("abcdefg"));
  /**
     checkedRules: ['lowercase']
      length: 7
      value: "tooWeak"
   */
  console.log(checkPasswordComplexity("abcdefg8"));
  /**
     checkedRules: ['lowercase', 'number']
      length: 8
      value: "weak"
   */
  console.log(checkPasswordComplexity("abcdefgh9"));
  /**
     checkedRules: ['minLength', 'lowercase', 'number']
      length: 9
      value: "medium"
   */
  console.log(checkPasswordComplexity("abcdefgh9F="));
  /**
     checkedRules: ['minLength', 'lowercase', 'uppercase', 'number', 'specialCharacter']
      length: 11
      value: "strong"
   */

Options

property type Default value Description
minLength number 8 Number of minimum character
allowedSpecialChar string !@#$%^&*(),.?":{}<>\[\]\\/`~;'_+=- regex for the special character to use

  console.log(checkPasswordComplexity("abcdefg", { minLength: 6 }));
  /**
     checkedRules: ['minLength', 'lowercase']
      length: 7
      value: "weak"
   */

   // example: "." is the special character to be allowed
  console.log(checkPasswordComplexity("abcdefg.", { allowedSpecialChar: "." }));
  /**
     checkedRules: ['lowercase', 'specialCharacter']
      length: 8
      value: "weak"
   */

Contributing

Contributions & pull requests are welcome! Get started here.

If you find this project useful, don't forget to give a ★ on GitHub