gregorj/correct-horse

受到Randall Munroe的XKCD #936启发的随机密码生成器

v1.1.3 2022-03-21 16:07 UTC

This package is auto-updated.

Last update: 2024-09-21 21:55:00 UTC


README

License: MIT Maintainability Test Coverage Packagist Version

受到Randall Munroe的XKCD #936bbusschots/hsxkpasswdmatt-allan/battery-staple启发的随机密码生成器。感谢!

为什么?

我需要一个PHP中分发初始密码的生成器。密码不应容易被猜测,特别是对于电脑,接收密码的人应该能够快速且无误地输入密码。

激发许多人灵感的漫画

To anyone who understands information theory and security and is in an infuriating argument with someone who does not (possibly involving mixed case), I sincerely apologize.

词典

此仓库包含一个基于Juergen Vierheilig的GPL许可的WinEdit德语词典的德语单词列表,来源于Crypt::HSXKPasswd::Dictionary::DE。我尝试清除了单词列表中的NSFW词语。

为了添加词典,可以实现\GregorJ\CorrectHorse\DictionaryInterface接口,或者将文件复制到dict目录并使用\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

测试

每个类都有单元测试。

docker run \
    --init \
    --rm \
    --volume $(pwd):/app \
    --workdir /app \
    php:7.2 vendor/bin/phpunit