Closed tomsommer closed 8 years ago
I believe I already have the option to set min and max length of the words.
The default is between 3 and 20 characters.
An example would be configured like this:
use Hackzilla\PasswordGenerator\Generator\HumanPasswordGenerator;
$generator = new HumanPasswordGenerator();
$generator
->setWordList('/usr/share/dict/words')
->setMinWordLength(3)
->setMaxWordLength(20)
->setWordCount(3)
->setWordSeparator('-');
$password = $generator->generatePasswords(10);
Right, I know. But I can't get a 20 char password consisting of 3 or more random words with the above. As far as I can tell, anyway.
I'll have a think.
It'll be possible to limit the password length.
I've added a branch with all the boiler plate code.
If you can think of a good way to generate a password of a fixed length, then I'm open to suggestions.
HumanPasswordGenerator.php#L123
This is my current work in progress.
$desiredLength = $this->getLength() || $this->getMaxPasswordLength();
for ($i = 0; $i < $wordCount; $i++) {
if ($i) {
$password .= $this->getWordSeparator();
}
if ($this->getLength()) {
$minLength = $this->getMinWordLength();
$maxLength = $this->getMaxWordLength();
$password .= $this->randomWord($minLength, $maxLength);
} else {
$password .= $this->randomWord();
}
}
This feature is currently in the develop branch, waiting for release.
Though I need to tweak it. Currently if you request a password of 30 characters, with 3 words; it is possible it will look for 28 character. I need check the maximum word length before release.
In release 1.2.0
You can set the number of words, but it would be nice if you could set the minimum length of the words, and the max length of the password.
Or be able to set the max length of the password, and the minimum number of words in it.