File: /home/aliazzsr/api.crm.vqode.com/components/validators/PasswordValidator.php
<?php
namespace app\components\validators;
use yii\validators\Validator;
class PasswordValidator extends Validator
{
private $passwordRules = [
'^.{8,}$' => '{attribute} must be at least 8 characters',
'^.{8,255}$' => '{attribute} must be at most 255 characters',
'[a-z]' => '{attribute} must contain at least 1 lowercase letter',
'[A-Z]' => '{attribute} must contain at least 1 uppercase letter',
'[0-9]' => '{attribute} must contain at least 1 number',
];
public function validateAttribute($model, $attribute)
{
$password = $model->{$attribute};
foreach ($this->passwordRules as $rule => $message) {
if (!preg_match("/{$rule}/", $password)) {
$this->addError($model, $attribute, $message);
}
}
}
}