plusforta/password-generator

PHP library for generating easy to remember but hard to guess passwords

Installs: 297

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

pkg:composer/plusforta/password-generator

v1.1.1 2025-11-24 13:18 UTC

This package is auto-updated.

Last update: 2025-12-24 12:25:50 UTC


README

A flexible and scriptable password generator which generates strong passphrases, inspired by XKCD Comic 936. Generated passwords easy to remember, but hard to guess passwords.

XKCD Password Strength

Note: This is a modernized fork of the original password-generator by 27cm/KarelWintersky, updated for PHP 8.3+ compatibility.

Installing

With Composer:

$ composer require plusforta/password-generator

Basic usage

Library generates phrases from frequently used words:

  • English phrases (example "throat-fast-only-idea")
  • German phrases (example "laut-welt-ganze-liter")

Generate password with default length (4 words) and default separator (dash).

use Plusforta\Password\Generator;

// Generate English password (default: 4 words with dash separator)
echo Generator::generateEn();
// => "throat-fast-only-idea"

// Generate German password (default: 4 words with dash separator)
echo Generator::generateDe();
// => "laut-welt-ganze-liter"

// Custom length
echo Generator::generateEn(6);
// => "ritual-error-raise-arab-tail-happy"

// Custom separator (space)
echo Generator::generateEn(4, ' ');
// => "throat fast only idea"

// Custom separator (underscore)
echo Generator::generateDe(4, '_');
// => "laut_welt_ganze_liter"

Exporting word lists

You can access and export the complete word list from any WordList class:

use Plusforta\Password\WordList\En;
use Plusforta\Password\WordList\De;

// Get all words from English word list
$en = new En();
$allWords = $en->getWords();
// => array of 2048 English words

// Get all words from German word list
$de = new De();
$allWords = $de->getWords();
// => array of 2048 German words

// Filter words by prefix (case-insensitive)
$wordsStartingWithAn = $en->getWords('an');
// => array of words starting with "an" (e.g., "and", "animal", "answer")

// Uppercase prefix works the same way
$sameWords = $en->getWords('AN');
// => same result as lowercase "an"

// Export to JSON
echo json_encode($en->getWords());

// Export words starting with specific prefix
echo json_encode($en->getWords('pre'));

Word lists

English

List of 2048 most frequently used English words.

ClassCommentWord lenghthExample
WordList\Enall words4-6have, that
WordList\En\Nounsnouns4-6time, year
WordList\En\Verbsverbs4-6have, would
WordList\En\Adjectivesadjectives4-8other, good

German

List of 2048 most frequently used German words (source). Words with diacritic letters (ä, ö, ü) and eszett (ß) excluded.

ClassCommentWord lenghthExample
WordList\Deall words4-6sich, nicht

Security

Library uses CSPRNG for random number generation.