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

custom-password-strength-checker

v1.0.0

Published

check-password-strength is a customizable npm package to assess the strength of a password based on specific requirements. It provides feedback on password strength, suggestions for improvement, and allows for custom messages to fit your application's nee

Readme

Check Password Strength

checkPasswordStrength is a customizable npm package to assess the strength of a password based on specific requirements. It provides feedback on password strength, suggestions for improvement, and allows for custom messages to fit your application's needs.

Installation

npm install check-password-strength

Usage

Import the checkPasswordStrength function and call it with a password string and an optional configuration object.

Example

const checkPasswordStrength = require("check-password-strength");

const feedback = checkPasswordStrength("Test@123", {
  minLength: 10,
  requireNumbers: true,
  requireSpecialChars: true,
  requireUppercase: true,
  requireLowercase: true,
  disallowCommonPasswords: true,
  customMessages: {
    minLength: "Password should be at least 10 characters long.",
    requireNumbers: "Include at least one numerical digit.",
    commonPassword:
      "This password is too commonly used, choose something unique.",
  },
});

console.log(feedback);

Output:

The function returns an object with the following properties:

{
  "score": 4,
  "strength": "Strong",
  "suggestions": ["Password should be at least 10 characters long."]
}

Options

The checkPasswordStrength function accepts a configuration object with the following options:

  • minLength (default: 8): Minimum length required for the password.
  • requireNumbers (default: true): Requires at least one number in the password.
  • requireSpecialChars (default: true): Requires at least one special character.
  • requireUppercase (default: true): Requires at least one uppercase letter.
  • requireLowercase (default: true): Requires at least one lowercase letter.
  • disallowCommonPasswords (default: false): Prevents the use of commonly used passwords like "123456", "password", etc.
  • customMessages (default: {}): Custom messages for different requirements. Useful for localization or personalization.

Feedback Structure

The feedback object returned by checkPasswordStrength contains:

  • score: A numeric score based on the password's compliance with the specified criteria.
  • strength: A descriptive strength level based on the score:
    • Weak (score <= 2)
    • Moderate (score === 3)
    • Strong (score === 4)
    • Very Strong (score >= 5)
  • suggestions: An array of strings with suggestions for making the password stronger based on the unmet criteria.

Custom Error Messages

You can customize error messages using the customMessages object in the options. The custom messages object can have the following keys:

  • minLength: Custom message when the password does not meet the minimum length.
  • requireNumbers: Custom message when a number is required but not included.
  • requireSpecialChars: Custom message when a special character is required but not included.
  • requireUppercase: Custom message when an uppercase letter is required but not included.
  • requireLowercase: Custom message when a lowercase letter is required but not included.
  • commonPassword: Custom message when the password is flagged as too common.

Example with Custom Messages

const feedback = checkPasswordStrength("password123", {
  minLength: 12,
  disallowCommonPasswords: true,
  customMessages: {
    minLength: "Please make your password at least 12 characters long.",
    commonPassword:
      "This password is too commonly used, please choose another one.",
  },
});

console.log(feedback);

Output:

{
  "score": 2,
  "strength": "Weak",
  "suggestions": [
    "Please make your password at least 12 characters long.",
    "This password is too commonly used, please choose another one."
  ]
}

License

MIT License

This markdown is ready for use as a `README.md` file. It provides clear instructions, usage examples, and details on customization options for your password strength checker package.