Skip to content

Passphrase Generation

The PassphraseGenerator creates memorable yet secure passphrases using the EFF diceware wordlists.

use Cline\Keyphrase\Generators\PassphraseGenerator;
// Using static factory method
$passphrase = PassphraseGenerator::create()->generate();
// Using constructor
$generator = new PassphraseGenerator();
$passphrase = $generator->generate();
// Default is 6 words
$passphrase = PassphraseGenerator::create()->generate();
// Custom word count
$passphrase = PassphraseGenerator::create()
->words(8)
->generate();

Recommended word counts:

  • 4 words: ~51 bits entropy (basic security)
  • 6 words: ~77 bits entropy (standard security)
  • 8 words: ~103 bits entropy (high security)
  • 10 words: ~129 bits entropy (maximum security)

Three EFF diceware wordlists are available:

7,776 words, optimized for security:

$passphrase = PassphraseGenerator::create()
->large()
->generate();
// Example: "correct-horse-battery-staple-cloud-mint"

1,296 shorter, more memorable words:

$passphrase = PassphraseGenerator::create()
->short()
->generate();
// Example: "oak-tip-red-sun-bay-ice"

1,296 words with unique 3-character prefixes (easier autocomplete):

$passphrase = PassphraseGenerator::create()
->uniquePrefix()
->generate();
// Example: "abs-bea-cli-dry-elm-fig"
use Cline\Keyphrase\Enums\EFFWordList;
$passphrase = PassphraseGenerator::create()
->useWordList(EFFWordList::Short)
->generate();

Hyphen is the default separator:

$passphrase = PassphraseGenerator::create()->generate();
// Example: "word-word-word-word-word-word"
$passphrase = PassphraseGenerator::create()
->separator('_')
->generate();
// Example: "word_word_word_word_word_word"
$passphrase = PassphraseGenerator::create()
->separator('.')
->generate();
// Example: "word.word.word.word.word.word"
$passphrase = PassphraseGenerator::create()
->withSpaces()
->generate();
// Example: "word word word word word word"
$passphrase = PassphraseGenerator::create()
->noSeparator()
->generate();
// Example: "wordwordwordwordwordword"
$passphrase = PassphraseGenerator::create()
->titleCase()
->generate();
// Example: "Correct-Horse-Battery-Staple-Cloud-Mint"
$passphrase = PassphraseGenerator::create()
->uppercase()
->generate();
// Example: "CORRECT-HORSE-BATTERY-STAPLE-CLOUD-MINT"
$passphrase = PassphraseGenerator::create()
->lowercase()
->generate();
// Example: "correct-horse-battery-staple-cloud-mint"

Add a random number to the passphrase for additional entropy:

$passphrase = PassphraseGenerator::create()
->words(4)
->includeNumber()
->generate();
// Example: "correct-42-horse-battery-staple"

The number is inserted at a random position among the words.

$passphrases = PassphraseGenerator::create()
->words(6)
->titleCase()
->generateMany(5);
// Returns array of 5 unique passphrases
$generator = PassphraseGenerator::create()
->words(6)
->large();
$entropy = $generator->entropy();
// Returns: ~77.55 bits
// Including a number adds entropy
$entropy = PassphraseGenerator::create()
->words(6)
->includeNumber()
->entropy();
// Returns: ~81 bits
use Cline\Keyphrase\Generators\PassphraseGenerator;
// Create a passphrase generator with common settings
$generator = PassphraseGenerator::create()
->words(6)
->large()
->titleCase()
->separator('-');
// Generate passphrases
$passphrase1 = $generator->generate();
$passphrase2 = $generator->generate();
// Check entropy
$entropy = $generator->entropy();
echo "Passphrase entropy: {$entropy} bits";
// Generate with number for extra security
$withNumber = $generator->includeNumber()->generate();

Passphrases offer several advantages over traditional passwords:

  1. Memorability: Words are easier to remember than random characters
  2. Typing Speed: Familiar words are faster to type
  3. Security: Long passphrases have excellent entropy
  4. Resistance: Harder to shoulder-surf than short passwords
TypeExampleEntropyMemorability
8-char passwordK9#mPx$2~52 bitsHard
6-word passphrasecorrect-horse-battery-staple-cloud-mint~77 bitsEasy
12-char passwordK9#mPx$2nQwR~79 bitsVery Hard