Files
laravel-gost-template/app/Support/PasswordPolicy.php
2026-06-24 17:20:43 +09:00

56 lines
1.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Support;
use Illuminate\Validation\Rules\Password;
/**
* Единая парольная политика приложения (мера ИАФ.3).
*
* Параметры берутся из config/security.php → password. Использовать во всех
* Form Request'ах, где задаётся/меняется пароль, чтобы политика была единой.
*/
class PasswordPolicy
{
public static function rule(): Password
{
$cfg = config('security.password');
$rule = Password::min((int) $cfg['min_length']);
if ($cfg['require_mixed_case']) {
$rule->mixedCase();
}
if ($cfg['require_numbers']) {
$rule->numbers();
}
if ($cfg['require_symbols']) {
$rule->symbols();
}
if ($cfg['check_compromised']) {
$rule->uncompromised();
}
return $rule;
}
/**
* Количество хранимых в истории паролей (запрет повтора).
*/
public static function historyLimit(): int
{
return (int) config('security.password.history_limit');
}
/**
* Срок действия пароля в днях (0 — без ограничения).
*/
public static function maxAgeDays(): int
{
return (int) config('security.password.max_age_days');
}
}