Autoría | Ultima modificación | Ver Log |
<?php
declare(strict_types=1);
namespace LeadersLinked\Validator;
use Laminas\Validator\AbstractValidator;
class PasswordStrengthCheck extends AbstractValidator
{
const PATRON = '/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$^x%x*-]).{6,16}$/';
const INVALID = 'Invalid';
/**
* Validation failure message template definitions
*
* @var array
*/
protected $messageTemplates = [
self::INVALID => 'Must contain at least one number, one letter, one uppercase letter and between 6 and 16 characters',
];
/**
* Returns true if and only if $value contains only hexadecimal digit characters
*
* @param string $value
* @return bool
*/
public function isValid($value)
{
$matches = [];
preg_match (self::PATRON, $value, $matches);
if (empty($matches)) {
$valid = false;
$this->error(self::INVALID);
} else {
$valid = true;
$this->setValue($matches[0]);
}
return $valid;
}
}