🔒 Passwords made easy in Filament PHP 🤫
MIT License
🔒 Passwords made easy in Filament PHP 🤫
This package allows you to add a feature rich password input/field for Filament PHP.
https://packagist.org/packages/discoverydesign/filament-locksmith
elephant-plant-photo
.composer require discoverydesign/filament-locksmith
use DiscoveryDesign\FilamentLocksmith\Forms\Components\PasswordInput
.PasswordInput
form component to your form with PasswordInput::make()
.php artisan vendor:publish --tag=filament-locksmith-translations
.<?php
namespace App\Filament\Resources;
use DiscoveryDesign\FilamentLocksmith\Forms\Components\PasswordInput;
// ...
class UserResource extends Resource
{
// ...
public static function form(Form $form): Form
{
return $form
->schema([
PasswordInput::make('password')
->required()
->generatable()
->friendly()
->copyable()
->revealable(),
// ...
]);
}
// ...
}
PasswordInput::make('password')
->required()
->advanced()
->copyable()
->revealable(),
PasswordInput::make('password')
->required()
->advanced()
->setGenerators([
new DiscoveryDesign\FilamentLocksmith\Generators\RandomGenerator,
new DiscoveryDesign\FilamentLocksmith\Generators\MemorableGenerator
])
->copyable()
->revealable(),
->generatable($state)
generatable
can be used to set if this password field should allow for an automatic password to be generated. This by default will generate a 32 character random string.
state
- (optional, bool) If the password should be generatable.
->friendly()
friendly
is a preloaded generator that creates a user friendly password. This password consists of 3 words that are combinred with '-'. E.g time-shelf-bottle
->copyable($state)
copyable
can be used to set if this password field should copyable to clipboard.
state
- (optional, bool) If the password should be copyable.
->editable($state)
editable
can be used to block the password field being edited. This is normally combined with ->generatable()
.
state
- (optional, bool) If the password should be editable.
->generator($func)
generator
allows you to define a custom generator that is used to create a password.
func
- (optional, closure | bool) The function used to generate the password. This function must return a string.
->hashed($state)
hashed
can be used if the password should be hashed before being stored. In most cases, you should instead use a cast against your model.
state
- (optional, bool) If the password should be hashed.
->revealable($func)
revealable
can be used to allow the password to be revealed. This is just Filament's built in reveal functionality.
func
- (optional, closure | bool) If the password should be revealable. If a closure is passed, this should return a bool.
->advanced()
advanced
will enable advanced mode which allows user configuration of their password, along with a selection of different password types.
state
- (optional, bool) If the password should be hashed.
->addGenerator($generator)
addGenerator
can be used to add a generator to the advance mode password generator. You should pass in an instance of a class that extends DiscoveryDesign\FilamentLocksmith\Generators\BaseGenerator
.
generator
- (class, extends BaseGenerator) The generator to add.
->setGenerators($generators)
setGenerators
will override all existing generators assigned to this PasswordInput and instead use the ones passed in. You should pass in an array of instances of a class that extends DiscoveryDesign\FilamentLocksmith\Generators\BaseGenerator
.
generators
- (array) The generators to set.
->getGenerators()
getGenerators
can be used to get an array of all the current generators.
If you want to create a generator, you should first start by creating a new class that extends DiscoveryDesign\FilamentLocksmith\Generators\BaseGenerator
.
Inside your __construct
you should include any options that you want to use to generate the password. It is encouraged to use a unique name for your form inputs.
The generate
function should return a string that is the password.
<?php
namespace App\Filament\Locksmith\Generators;
use Filament\Forms;
use DiscoveryDesign\FilamentLocksmith\Generators\BaseGenerator;
use Illuminate\Support\Str;
class MyCustomGenerator extends BaseGenerator
{
public string $name = 'My Custom Generator';
public function __construct()
{
$this->setOptions([
Forms\Components\TextInput::make('mygenerator_length')
->label('length')
->default(20)
->type('number')
->required()
]);
}
public function generate($get)
{
$length = $get('mygenerator_length');
return Str::password($length);
}
}
You can then add this generator to your password input with ->addGenerator(new MyCustomGenerator)
.
🚀 Discovery Design