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-strength-tester

v1.0.4

Published

A customizable password strength checker and generator

Downloads

356

Readme

Password Strength Tester

A powerful and customizable password strength checker and generator for Node.js applications. This module provides both password strength validation and customizable password generation capabilities.

Features

  • 🔒 Comprehensive password strength checking
  • 🎯 Customizable password generation
  • 📊 Detailed strength scoring system
  • 🔄 Multiple character sets support
  • 📝 TypeScript support
  • 🚀 Zero dependencies
  • ⚡ Lightweight and fast
  • 🧪 Well-tested

Installation

npm install password-strength-tester

Usage

const { check, generateStrongPassword } = require("password-strength-tester");

// Check password strength
const strengthResult = check("MyPassword123!");
console.log(strengthResult);
// Output: { strength: 'Strong', score: 85 }

// Generate a password with default settings
const password = generateStrongPassword();
console.log(password);
// Output: "Kx7#mN!9p"

Password Strength Checking

The check function evaluates passwords based on multiple criteria:

const result = check("YourPassword123!");
console.log(result);

Returns an object with:

  • strength: Text representation of password strength
  • score: Numerical score (0-100)
  • suggestion: Generated password suggestion (only for weak passwords)

Strength Levels

  • Very Strong (90-100)
  • Strong (70-89)
  • Medium (50-69)
  • Weak (30-49)
  • Very Weak (0-29)

Scoring Criteria

  • Length (minimum and extra points)
  • Character variety
  • Sequential characters
  • Common patterns
  • Mixed character types bonus

Password Generation

Basic Usage

// Default configuration (9 characters)
const password = generateStrongPassword();

// Custom length
const longPassword = generateStrongPassword({ length: 16 });

Advanced Configuration

const customPassword = generateStrongPassword({
  length: 12,
  charCounts: {
    upper: 3, // uppercase letters
    lower: 4, // lowercase letters
    numbers: 3, // numeric digits
    special: 2, // special characters
  },
});

Configuration Options

interface PasswordConfig {
  length?: number; // Total length (default: 9)
  charCounts?: {
    upper?: number; // Uppercase count (default: 2)
    lower?: number; // Lowercase count (default: 3)
    numbers?: number; // Numbers count (default: 2)
    special?: number; // Special chars count (default: 2)
  };
}

Special Use Cases

// Only uppercase and numbers
const uppercaseNumbers = generateStrongPassword({
  length: 10,
  charCounts: {
    upper: 5,
    lower: 0,
    numbers: 5,
    special: 0,
  },
});

// Only lowercase letters
const lowercaseOnly = generateStrongPassword({
  length: 8,
  charCounts: {
    upper: 0,
    lower: 8,
    numbers: 0,
    special: 0,
  },
});

// Extra special characters
const specialHeavy = generateStrongPassword({
  length: 12,
  charCounts: {
    special: 4,
  },
});

Character Sets

Default character sets used for generation:

  • Uppercase: A-Z
  • Lowercase: a-z
  • Numbers: 0-9
  • Special: !@#$%^&*()_+-=[]{}|;:,.<>?

Error Handling

The module throws errors for invalid inputs:

try {
  const password = generateStrongPassword({
    length: 5,
    charCounts: {
      upper: 10, // Error: exceeds total length
    },
  });
} catch (error) {
  console.error(error.message);
  // "Total character counts cannot exceed password length"
}

TypeScript Support

Full TypeScript support with type definitions included:

import { check, generateStrongPassword } from "password-strength-tester";

interface PasswordResult {
  strength: string;
  score: number;
  suggestion?: string;
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Steps to Contribute

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Author

ErenayFC

Support

If you found this project helpful, please give it a ⭐!