Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to set max length of HumanPasswordGenerator #12

Closed
tomsommer opened this issue Oct 19, 2015 · 6 comments
Closed

Ability to set max length of HumanPasswordGenerator #12

tomsommer opened this issue Oct 19, 2015 · 6 comments

Comments

@tomsommer
Copy link

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.

@hackzilla
Copy link
Owner

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);

@tomsommer
Copy link
Author

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.

@hackzilla
Copy link
Owner

I'll have a think.

It'll be possible to limit the password length.

@hackzilla
Copy link
Owner

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();
            }
        }

hackzilla added a commit that referenced this issue May 2, 2016
set length for human password generator
@hackzilla
Copy link
Owner

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.

hackzilla added a commit that referenced this issue May 5, 2016
@hackzilla
Copy link
Owner

In release 1.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants