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!');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|