megahunt.test/app/Rules/ZxcvbnRule.php

25 lines
595 B
PHP
Raw Permalink Normal View History

2024-08-30 00:46:03 +02:00
<?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;
2024-08-30 09:40:57 +02:00
$zxcvbn = new Zxcvbn;
2024-08-30 00:46:03 +02:00
if ($zxcvbn->passwordStrength($value)['score'] < 3) {
$fail('Password is not secure enough!');
}
}
}