npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

password-ruler

v0.1.0

Published

An extensible & lightweight module that helps to easily create custom password strength checkers

Downloads

28

Readme

PasswordRuler Build Status Coverage Status

What does it do?

It helps you easily create a customized password complexity calculator, and furthermore, to build your own strength meter.

Why?

Because -almost- every company you work for has its own requirements & specifications.

Install

npm install --save password-ruler

Usage

Basic scenario

Let's say that you just want to have a basic complexity score:

const PasswordRuler = require('password-ruler');

// Constructor can take an object (one strength level)
// or an array of objects (length of array = number of levels).
// In this scenario, one strength level is fine:
const ruler = new PasswordRuler({
  minLength: { // a validator object has to have 2 props; "weight" & "validate"
    weight: 1, // basically the importance degree of validator
    validate: function(password) { // first argument is always the password
      return password.length > 3;
    }
  },
  containsAnUppercase: {
    weight: 2,
    validate: [Function]
  },
  containsASpecialCharacter: {
    weight: 2,
    validate: [Function]
  }
});

ruler.check('test');
// => {
//   score: 20,
//   strength: 0,
//   levels: [{
//     score: 20,
//     validator: {
//       minLength: true,
//       containsAnUppercase: false,
//       containsASpecialCharacter: false
//     }
//   }]
// }

ruler.check('Test');
// => {
//   score: 60,
//   strength: 0,
//   levels: [{
//     score: 60,
//     validator: {
//       minLength: true,
//       containsAnUppercase: true,
//       containsASpecialCharacter: false
//     }
//   }]
// }

ruler.check('Test*');
// => {
//   score: 100,
//   strength: 1,
//   levels: [{
//     score: 100,
//     validator: {
//       minLength: true,
//       containsAnUppercase: true,
//       containsASpecialCharacter: true
//     }
//   }]
// }

Multiple strength-levels

Let's rapidly create a password strength meter that has 3 levels, using PasswordRuler Add-ons:

const {
  containsUpperCase,
  containsDigit,
  containsSpecialChar,
  excludesSequentialDigits,
  excludesBirthDate
} = require('password-ruler-addons'); // see above link for all available methods

const ruler = new PasswordRuler([
  { // 1st level (Weak):
    uppercase: containsUpperCase(), // Add-ons methods always return a validator
    number: containsDigit()
  },
  { // 2nd level:
    special: containsSpecialChar(2, 3), // => weight: 3 (the value comes after required parameters sets the weight of validator)
    sequential: excludesSequentialDigits(4), // excludes 4 digits, weight is still 1 as default
  },
  { // 3rd level (Strong)
    birthdate: excludesBirthDate()
  }
]);

ruler.check('**Test1234');
// => {
//   score: 71, // overall score that is calculated based on validator weights
//   strength: 1, // makes only the 1st level: weak
//   levels: [
//     {
//       score: 100,
//       validator: {
//         uppercase: true,
//         number: true
//       }
//     },
//     {
//       score: 75, // individual level score
//       validator: {
//         special: true,
//         sequential: false
//       }
//     },
//     {
//       score: 0,
//       validator: {
//         birthdate: undefined
//       }
//     }
//   ]
// }

API

addLevel(level) ⇒ PasswordRuler

Adds a new level on top of existing levels.

Kind: instance method of PasswordRuler Returns: PasswordRuler - PasswordRuler instance's itself

| Param | Type | Description | | --- | --- | --- | | level | Object | A level object with one or multiple validators |

addValidator(name, validate, weight, [levelIndex]) ⇒ PasswordRuler

Adds a new validator to the given or last level.

Kind: instance method of PasswordRuler Returns: PasswordRuler - PasswordRuler instance's itself

| Param | Type | Description | | --- | --- | --- | | name | String | Validator name | | validate | function | Validation function | | weight | Integer | Validator importance rate | | [levelIndex] | Integer | Index of level (If it is not available, validator will be added to the last level) |

check(password) ⇒ Object

Checks the given password & provides a result object

Kind: instance method of PasswordRuler Returns: Object - A result object that contains score, strenght & level props

| Param | Type | Description | | --- | --- | --- | | password | String | Password to check |

PasswordRuler.init(passwordRuler, levels)

Applies each given levels to the given PasswordRuler instance

Kind: static method of PasswordRuler

| Param | Type | Description | | --- | --- | --- | | passwordRuler | PasswordRuler | An instance of PasswordRuler | | levels | Array | Object | A level list with validators or a single level object |

Related

License

MIT http://tameraydin.mit-license.org/