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

Specify character list #21

Closed
poxin13 opened this issue May 18, 2017 · 4 comments
Closed

Specify character list #21

poxin13 opened this issue May 18, 2017 · 4 comments

Comments

@poxin13
Copy link

poxin13 commented May 18, 2017

I have a specific requirement where in I can only use certain special characters. Is there anyway to specify what ones will be used when generating a password?

Another odd requirement is my first character must be alphanumeric, but I can do this after with substr.

@poxin13 poxin13 changed the title Set characters that are used Specify character list May 18, 2017
@hackzilla
Copy link
Owner

There is one main way to do it.
I'm assuming that we are talking about the ComputerPasswordGenerator

https://github.com/hackzilla/password-generator/blob/master/Generator/ComputerPasswordGenerator.php#L26

  $generator = (new ComputerPasswordGenerator())->setParameter(self::PARAMETER_UPPER_CASE, 'AZ')

or you can extend ComputerPasswordGenerator and override the constructor with your own config.

@poxin13
Copy link
Author

poxin13 commented May 18, 2017

Apologies, should have specified I'm using the RequirementPasswordGenerator. It's come in pretty handy as applications we use have very specific password requirements.

@hackzilla
Copy link
Owner

hackzilla commented May 18, 2017

It'll be the same with RequirementPasswordGenerator, as that extends ComputerPasswordGenerator anyway.

If you override the contractor you will need to call the parent.

class MyPasswordGenerator extends RequirementPasswordGenerator
{
    /**
     */
    public function __construct()
    {
        parent::__construct();
        $this
            ->setParameter(self::PARAMETER_UPPER_CASE, 'AZ')
            ->setParameter(self::PARAMETER_LOWER_CASE, 'az')
            ->setParameter(self::PARAMETER_NUMBERS, '0123789')
            ->setParameter(self::PARAMETER_SYMBOLS, '!@+');
    }
}

@poxin13
Copy link
Author

poxin13 commented May 18, 2017

Using setParameter worked fine, thanks!

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

No branches or pull requests

2 participants