F
Filament11mo ago
caglar

How to replace a password with asteriks in an infolist but keep the value to copy

I have a password field in my infolist and I'd like to convert it into asteriks like ** but at the same time I want to keep it copyable with its real value
TextEntry::make('password')
->label('Password')
->getStateUsing(fn ($record) => $record->credentials()->where('loginunpw', 1)->first()->pass)
->copyable()
->copyMessage('Copied!'),
TextEntry::make('password')
->label('Password')
->getStateUsing(fn ($record) => $record->credentials()->where('loginunpw', 1)->first()->pass)
->copyable()
->copyMessage('Copied!'),
5 Replies
caglar
caglarOP11mo ago
TextEntry::make('password')
->label('Password')
->getStateUsing(function ($record) {
$password = $record->credentials()->where('loginunpw', 1)->first()->pass;
return Str::mask($password, '*', 0);
})
->copyable()
->copyMessage('Copied!'),
TextEntry::make('password')
->label('Password')
->getStateUsing(function ($record) {
$password = $record->credentials()->where('loginunpw', 1)->first()->pass;
return Str::mask($password, '*', 0);
})
->copyable()
->copyMessage('Copied!'),
I found Str::mask() method but I couldn't understand that it does keep the password value?
LeandroFerreira
LeandroFerreira11mo ago
use formatStateUsing getStateUsing will change the state
->formatStateUsing(fn ($state): string => Str::mask($state, '*', '0'))
->formatStateUsing(fn ($state): string => Str::mask($state, '*', '0'))
caglar
caglarOP11mo ago
TextEntry::make('password')
->label('Password')
->getStateUsing(fn ($record) => $record->credentials()->where('loginunpw', 1)->first()->pass)
->formatStateUsing(fn ($state): string => Str::mask($state, '*', '0'))
->copyable()
->copyMessage('Copied!'),
TextEntry::make('password')
->label('Password')
->getStateUsing(fn ($record) => $record->credentials()->where('loginunpw', 1)->first()->pass)
->formatStateUsing(fn ($state): string => Str::mask($state, '*', '0'))
->copyable()
->copyMessage('Copied!'),
I changed my code like this. When I copy the password what the value will be. Real password value or just asteriks like **? I can't test it because I'm working on http and so I can't copy the value.
LeandroFerreira
LeandroFerreira11mo ago
hum, not sure what copyable will use as a value.. There is a copyableState that you can also use
caglar
caglarOP11mo ago
Here is the last version of my code. I hope it works. Thanks @Leandro Ferreira .
TextEntry::make('password')
->label('Password')
->getStateUsing(fn ($record) => $record->credentials()->where('loginunpw', 1)->first()->pass)
->formatStateUsing(fn ($state): string => Str::mask($state, '*', '0'))
->copyable()
->copyableState(fn (string $state): string => $state)
->copyMessage('Copied!'),
TextEntry::make('password')
->label('Password')
->getStateUsing(fn ($record) => $record->credentials()->where('loginunpw', 1)->first()->pass)
->formatStateUsing(fn ($state): string => Str::mask($state, '*', '0'))
->copyable()
->copyableState(fn (string $state): string => $state)
->copyMessage('Copied!'),
Want results from more Discord servers?
Add your server