A random passphrase generator inspired by Randall Munroes XKCD #936, bbusschots/hsxkpasswd, and matt-allan/battery-staple. Thanks!
I needed a generator for handing out initial passwords in PHP. The password should not be easy to guess, especially not for a computer, and the person receiving the password should be able to enter the password fast and without mistakes.
This repository contains a German word list based on the GPL-licensed German dictionary for WinEdit by Juergen Vierheilig, copied from Crypt::HSXKPasswd::Dictionary::DE. I tried to rid the word list of NSFW words.
- 'dict-de-lc.txt' List of lower case German words.
- 'dict-de-uc.txt' List of upper case German words.
In order to add dictionaries, either implement the \GregorJ\CorrectHorse\DictionaryInterface
or just copy files into the dict directory and use \GregorJ\CorrectHorse\Dictionaries\DictionaryFile
.
composer require gregorj/correct-horse
<?php
require_once 'vendor/autoload.php';
use GregorJ\CorrectHorse\Dictionaries\DictionaryFile;
use GregorJ\CorrectHorse\Generators\RandomNumbers;
use GregorJ\CorrectHorse\Generators\RandomWord;
use GregorJ\CorrectHorse\Generators\RandomWords;
use GregorJ\CorrectHorse\Generators\RandomCharacter;
use GregorJ\CorrectHorse\PassphraseGenerator;
$passphrase = new PassphraseGenerator();
// separate the random items of the passphrase with a special character
$passphrase->setSeparator(new RandomCharacter(['-', '#', '.', ' ']));
// random numbers should be between 1 and 99
$randomNumbers = new RandomNumbers();
$randomNumbers->setMinAndMax(1,99);
// add one random number at the beginning
$passphrase->add($randomNumbers, 1);
// add 4 random lower or upper case words
$passphrase->add(
new RandomWords(
new RandomWord(new DictionaryFile('dict-de-lc.txt')),
new RandomWord(new DictionaryFile('dict-de-uc.txt'))
),
4
);
// finally, add another random number
$passphrase->add($randomNumbers, 1);
// now let's generate a random passphrase
echo $passphrase->generate().PHP_EOL;
//9 korrekt Pferd Batterie Heftklammer 36
There are unit tests for every class.
docker run \
--init \
--rm \
--volume $(pwd):/app \
--workdir /app \
php:7.2 vendor/bin/phpunit