38 lines
980 B
PHP
38 lines
980 B
PHP
<?php
|
|
|
|
namespace Modules\Admin\app\Rules;
|
|
|
|
use Closure;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Validation\Rules\Password;
|
|
|
|
class PasswordRule implements ValidationRule
|
|
{
|
|
/**
|
|
* Run the validation rule.
|
|
*/
|
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
{
|
|
$isLength = strlen($value) >= 8;
|
|
$isUppercase = preg_match('/[A-Z]/', $value);
|
|
$isNumber = preg_match('/[0-9]/', $value);
|
|
$isSymbol = preg_match('/\!|\@|\#|\$|\%|\^|\&|\*|\-/', $value);
|
|
if (!$isLength) {
|
|
$fail('Password must be at least 8 characters large.');
|
|
}
|
|
|
|
if (!$isUppercase) {
|
|
$fail('Password must have capital letters.');
|
|
}
|
|
|
|
if (!$isNumber) {
|
|
$fail('Password must have number.');
|
|
}
|
|
|
|
if (!$isSymbol) {
|
|
$fail('Password must have symbol ! @ # $ % ^ & * -');
|
|
}
|
|
}
|
|
}
|