1. Go to this page and download the library: Download nicobleiler/php-passphrase library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nicobleiler / php-passphrase example snippets
use NicoBleiler\Passphrase\Facades\Passphrase;
// Default: 3 words, hyphen separator, no capitalize, no number
Passphrase::generate();
// "candle-rubber-glimpse"
// Customize everything
Passphrase::generate(
numWords: 5,
wordSeparator: '.',
capitalize: true,
use NicoBleiler\Passphrase\PassphraseGenerator;
class AuthController
{
public function __construct(
private PassphraseGenerator $passphrase,
) {}
public function temporaryPassword(): string
{
return $this->passphrase->generate(
numWords: 4,
capitalize: true,
use NicoBleiler\Passphrase\PassphraseGenerator;
$generator = new PassphraseGenerator();
echo $generator->generate(); // "candle-rubber-glimpse"
use NicoBleiler\Passphrase\PassphraseGenerator;
use Random\Engine\Xoshiro256StarStar;
use Random\Randomizer;
$generator = new PassphraseGenerator(
randomizer: new Randomizer(new Xoshiro256StarStar(12345)),
);
// Same seed always produces the same passphrase
echo $generator->generate(); // deterministic output
$generator = new PassphraseGenerator();
// Entropy-based generation: numWords is calculated to reach at least 60 bits
echo $generator->generate(targetEntropyBits: 60);
return [
'num_words' => 3,
'word_separator' => '-',
'capitalize' => false,
' = bundled EFF long word list (7,776 words)
// Or provide your own word list as a PHP array of strings
'word_list' => null,
// Optional words to remove from the active word list
// Works with both bundled EFF and custom word_list values
'excluded_words' => [],
];
// config/passphrase.php
'word_list' => ['correct', 'horse', 'battery', 'staple'],
// Optionally remove specific words from the active list
'excluded_words' => ['horse'],
use NicoBleiler\Passphrase\WordList;
use NicoBleiler\Passphrase\PassphraseGenerator;
// From an array
$wordList = WordList::fromArray(['correct', 'horse', 'battery', 'staple']);
$generator = new PassphraseGenerator($wordList);
echo $generator->generate(numWords: 4);