megahunt.test/app/Rules/ZxcvbnRule.php

25 lines
597 B
PHP

<?php
namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use ZxcvbnPhp\Zxcvbn;
class ZxcvbnRule implements ValidationRule
{
/**
* Run the validation rule.
*
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$value = (string) $value;
$zxcvbn = new Zxcvbn();
if ($zxcvbn->passwordStrength($value)['score'] < 3) {
$fail('Password is not secure enough!');
}
}
}