php-tenant/Rules/CheckUserPasswordRule.php
Snider d0ad2737cb refactor: rename namespace from Core\Mod\Tenant to Core\Tenant
Simplifies the namespace hierarchy by removing the intermediate Mod
segment. Updates all 118 files including models, services, controllers,
middleware, tests, and composer.json autoload configuration.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 16:30:46 +00:00

45 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Core\Tenant\Rules;
use Closure;
use Core\Tenant\Models\User;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Hash;
/**
* Validates that the provided value matches the user's current password.
*
* This is typically used for password confirmation flows where a user
* must provide their current password before changing it or performing
* sensitive operations.
*/
class CheckUserPasswordRule implements ValidationRule
{
/**
* Create a new rule instance.
*
* @param User $user The user whose password should be checked
* @param string|null $message Optional custom error message
*/
public function __construct(
protected User $user,
protected ?string $message = null
) {}
/**
* Run the validation rule.
*
* @param string $attribute The attribute being validated
* @param mixed $value The value being validated
* @param Closure $fail Closure to call if validation fails
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (! Hash::check($value, $this->user->password)) {
$fail($this->message ?: 'The password is incorrect.');
}
}
}