2022-07-21 16:15:47 +02:00
|
|
|
<?php
|
2022-09-23 16:14:15 +02:00
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
namespace App\Validator;
|
|
|
|
|
|
|
|
use Symfony\Component\Validator\Constraint;
|
|
|
|
use Symfony\Component\Validator\ConstraintValidator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Annotation
|
|
|
|
*/
|
|
|
|
class PasswordValidator extends ConstraintValidator
|
|
|
|
{
|
|
|
|
public function validate($value, Constraint $constraint)
|
|
|
|
{
|
2022-09-23 16:14:15 +02:00
|
|
|
if (!empty($value)) {
|
2022-07-21 16:15:47 +02:00
|
|
|
if (strlen($value) < '8') {
|
|
|
|
$this->context->addViolation($constraint->message);
|
2022-09-23 16:14:15 +02:00
|
|
|
} elseif (!preg_match('#[0-9]+#', $value)) {
|
2022-07-21 16:15:47 +02:00
|
|
|
$this->context->addViolation($constraint->message);
|
2022-09-23 16:14:15 +02:00
|
|
|
} elseif (!preg_match('#[a-zA-Z]+#', $value)) {
|
2022-07-21 16:15:47 +02:00
|
|
|
$this->context->addViolation($constraint->message);
|
2022-09-23 16:14:15 +02:00
|
|
|
} elseif (!preg_match("/[|!@#$%&*\/=?,;.:\-_+~^\\\]/", $value)) {
|
2022-07-21 16:15:47 +02:00
|
|
|
$this->context->addViolation($constraint->message);
|
|
|
|
}
|
2022-09-23 16:14:15 +02:00
|
|
|
}
|
2022-07-21 16:15:47 +02:00
|
|
|
}
|
2022-09-23 16:14:15 +02:00
|
|
|
}
|