kristos80/password-generator

Secure, flexible password generator for PHP 8.2+

0.1.1 2025-04-17 11:14 UTC

This package is auto-updated.

Last update: 2025-04-17 11:15:41 UTC


README

A modern, flexible, and secure password generator built for PHP 8.2+. Designed with configuration-first principles, it supports character-type rules, avoidance of consecutive characters, and rich presets out of the box.

โœจ Features

  • PHP 8.2+ with readonly and strong types
  • Configurable character pools: lowercase, uppercase, numbers, symbols
  • Range-based character counts via PoolRange
  • Always start with a letter (optional)
  • Avoid consecutive characters (enabled by default)
  • Character exclusion (e.g., omit l, 1, 0, O)
  • Built-in presets (safe, strong, human-friendly, dev)
  • Pest-based test suite
  • Clean Composer autoloading (PSR-4)

โš™ Installation

composer require kristos80/password-generator

๐Ÿ“„ Usage

Basic Example

use Kristos80\PasswordGenerator\PasswordGenerator;
use Kristos80\PasswordGenerator\PasswordGeneratorFactory;

$config = PasswordGeneratorConfigFactory::safeDefault();
$password = (new PasswordGenerator())->generate($config);

echo $password;

๐Ÿ”ง Presets

safeDefault()

Balanced password with 3 lowercase, 2 uppercase, 2 numbers, 2 symbols. Avoids confusing characters like l, 1, 0, O.

strong()

16-20 character high-entropy password with balanced character pools.

humanFriendly()

No symbols, avoids ambiguous characters. Easier to type & read.

symbolHeavy()

Perfect for password vaults or power users. Focuses on symbol density.

developerPreset()

Ideal for API tokens: all alphanumeric, no symbols, fixed length.

โš–๏ธ Custom Configuration

You can define your own ranges:

use Kristos80\PasswordGenerator\PasswordGeneratorConfig;
use Kristos80\PasswordGenerator\PoolRange;

$config = new PasswordGeneratorConfig(
    new PoolRange(3, 5),   // lowercase
    new PoolRange(2, 4),   // uppercase
    new PoolRange(2, 2),   // numbers
    new PoolRange(1, 2),   // symbols
    true,                  // must start with a letter
    ['l', '1', '0', 'O']   // characters to exclude
);

Then:

$password = (new PasswordGenerator())->generate($config);

๐Ÿงฐ Built-in Logic

Consecutive Character Avoidance

Consecutive identical characters are avoided (e.g., aa, 11, $$), with up to 5 reshuffling attempts internally.

Start with Character

When enabled, the password will always begin with a letter (a-z or A-Z).

Exclusions

Characters passed via doNotUse will never appear in the final password, case-insensitively.

๐Ÿงช Testing

This package uses Pest for testing.

composer test

๐Ÿ“– License

MIT ยฉ Kristos80