1.0.4 โ€ข Published 2 months ago

password-strength-tester v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

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 โญ!