php-tenant/Rules/CheckUserPasswordRule.php
Snider 86dbf4e763 fix: namespace to Core\Mod\Tenant, restructure package
- Changed namespace from Core\Core\Tenant to Core\Mod\Tenant
- Moved src/ contents to root
- Removed Host UK extension files (admin.php, MemberManager, TeamManager)
- Fixed composer.json autoload paths
2026-01-27 00:58:42 +00:00

45 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Core\Mod\Tenant\Rules;
use Closure;
use Core\Mod\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.');
}
}
}