rawilk/filament-password-input
Installation:
composer require rawilk/filament-password-input
Publish the config (if needed):
php artisan vendor:publish --tag="filament-password-input-config"
First Use Case:
Replace a standard Filament TextInput with the enhanced password component in a form:
use Rawilk\FilamentPasswordInput\PasswordInput;
PasswordInput::make('password')
->label('New Password')
->required()
->maxLength(72)
Where to Look First:
Basic Integration:
Replace TextInput with PasswordInput in Filament forms (Pages, Widgets, or Resources):
PasswordInput::make('password')
->columnSpanFull() // Optional: Full-width layout
->extraAttributes(['autocomplete' => 'new-password']);
Dynamic Configuration: Use methods to customize behavior per field:
PasswordInput::make('confirm_password')
->revealPassword() // Enable toggle (default: true)
->copyToClipboard() // Enable clipboard (default: true)
->generatePassword() // Enable generator (default: true)
->passwordGeneratorLength(16); // Set default length
Resource-Specific Usage:
In a Filament Resource (e.g., UserResource):
public static function form(Form $form): Form
{
return $form
->schema([
PasswordInput::make('password')
->label('Reset Password')
->rules(['required_if:reset_password,1']),
]);
}
Widget/Page Integration:
For standalone forms (e.g., a PasswordResetPage):
public function form(Form $form): Form
{
return $form
->schema([
PasswordInput::make('new_password')
->passwordGeneratorRules(['uppercase', 'numbers']),
]);
}
Conditional Features: Disable features based on context (e.g., edit vs. create):
PasswordInput::make('password')
->copyToClipboard(fn ($record) => !$record->exists)
->generatePassword(fn ($record) => $record->isAdmin());
Custom Icons: Override default icons via config:
// config/filament-password-input.php
'icons' => [
'reveal' => 'heroicon-o-eye',
'copy' => 'heroicon-o-clipboard',
'generate' => 'heroicon-o-shuffle',
],
Password Generator Rules: Extend generator rules dynamically:
PasswordInput::make('password')
->passwordGeneratorRules(['custom_rule' => fn () => '!@#$%'])
->passwordGeneratorLength(20);
Localization: Translate labels/buttons via Filament’s localization system:
PasswordInput::make('password')
->revealPasswordLabel(fn () => __('filament-password-input::reveal'))
->copyLabel(fn () => __('filament-password-input::copy'));
v3.0 Migration:
composer require filament/filament:"^2.0"
config/filament-password-input.php. Update published config if using custom settings.Generator Security:
Str::random() by default, which may not meet all compliance needs (e.g., PCI DSS). Extend rules carefully:
->passwordGeneratorRules(['uppercase', 'lowercase', 'digits', 'special_chars'])
Clipboard Permissions:
Form Validation:
maxLength aligns with backend validation (e.g., Laravel’s max:72 for password fields). The component enforces UI limits but doesn’t replace server-side rules.Console Errors:
npm install @heroicons/react
filament-password-input related errors. Common causes:
x-data bindings).Configuration Overrides:
config/filament-password-input.php override defaults, but per-field methods (e.g., ->revealPassword(false)) take precedence.Testing:
$component = PasswordInput::make('test')
->revealPassword(false);
$this->assertFalse($component->isRevealPasswordEnabled());
type="text" ↔ type="password").Custom Actions: Extend the component via JavaScript (Alpine.js):
document.addEventListener('filament-password-input-initialized', (e) => {
const input = e.detail.input;
input.$el.querySelector('.generate-password').addEventListener('click', () => {
// Custom logic (e.g., API call for password)
});
});
Server-Side Logic:
Hook into Filament’s afterStateUpdated to log generated passwords (for audit trails):
use Filament\Forms\Concerns\InteractsWithForms;
public function form(Form $form): Form
{
return $form
->schema([PasswordInput::make('password')])
->afterStateUpdated(function (Form $form) {
if ($form->has('password') && $form->getState('password')) {
\Log::info('New password generated', ['password' => '***']);
}
});
}
Theming:
Override Blade views (e.g., resources/views/vendor/filament-password-input/...) to match your Filament theme:
<x-filament-password-input::input
:reveal-password="{{ $getRevealPassword() }}"
:copy-to-clipboard="{{ $getCopyToClipboard() }}"
:generate-password="{{ $getGeneratePassword() }}"
/>
Local Development:
npm run dev
php artisan filament:cache-clear
How can I help you explore Laravel packages today?