So, the back story.
I am currently building a password validation class for general use in Laminas applications via laminas-validator implementations. I believe that any time your working with Regex its good to get as many peoples thoughts as possible because there is so many approaches, ways to look at it, and, how to accomplish the task at hand. I am trying to figure out if there is a simpler way to accomplish this:
$options['special'] is the configuration options that are passed to the validator, in other words, if you set the options to require 2 special characters then that is how many we have to verify is present in $value. The current supported special characters are:
I am currently building a password validation class for general use in Laminas applications via laminas-validator implementations. I believe that any time your working with Regex its good to get as many peoples thoughts as possible because there is so many approaches, ways to look at it, and, how to accomplish the task at hand. I am trying to figure out if there is a simpler way to accomplish this:
$options['special'] is the configuration options that are passed to the validator, in other words, if you set the options to require 2 special characters then that is how many we have to verify is present in $value. The current supported special characters are:
Code:
[].+=\[\\\\@_!\#$%^&*()<>?|}{~:-]
PHP:
if (isset($options['special']) && (int) $options['special'] > 0) {
preg_match_all(self::POSSIBLE_SPECIAL_CHARS, $value, $specialMatches);
if (! count($specialMatches[0]) >= $options['special']) {
$this->error(self::INVALID_SPECIAL_COUNT);
$isValid = false;
}
}