web/app/Rules/IsCurrentPassword.php

43 lines
802 B
PHP

<?php
namespace App\Rules;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Contracts\Validation\Rule;
class IsCurrentPassword implements Rule
{
/**
* Create a new rule instance.
*
* @param User $user
* @return void
*/
public function __construct(
protected User $user
) {}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value): bool
{
return Hash::check($value, $this->user->password);
}
/**
* Get the validation error message.
*
* @return string
*/
public function message(): string
{
return __('Wrong password.');
}
}