Prevent old password as new password
I need help to tp prevent user entering the same old password as new password
<?php
namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Hash;
class NotSamePassword implements ValidationRule
{
protected $user;
public function __construct($user)
{
$this->user = $user;
}
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (Hash::check($value, $this->user->password)) {
$fail('The new password must be different from your current password.');
}
}
}<?php
namespace App\Filament\Pages\Auth;
use Filament\Forms\Components\Component;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Pages\Auth\EditProfile as BaseEditProfile;
use Filament\Pages\Dashboard;
class EditProfile extends BaseEditProfile
{
public function form(Form $form): Form{
return $form
->schema([
$this->getNameFormComponent(),
$this->getPhoneComponent(),
$this->getEmailFormComponent(),
$this->getPasswordFormComponent(),
$this->getPasswordConfirmationFormComponent()
]);
}
protected function getEmailFormComponent(): Component
{
return TextInput::make('email')
->label(__('filament-panels::pages/auth/edit-profile.form.email.label'))
->disabled()
->required()
->maxLength(255)
->unique(ignoreRecord: true);
}
protected function getPhoneComponent(): Component
{
return TextInput::make('phone')
->label('Phone')->disabled();
}
protected function getRedirectUrl(): ?string
{
return Dashboard::getUrl();
}
protected function mutateFormDataBeforeSave(array $data): array
{
$data['password_updated'] = true;
return $data;
}
}