Skip to content

Commit

Permalink
fix: imporove password generation
Browse files Browse the repository at this point in the history
  • Loading branch information
phpsa committed Aug 9, 2023
1 parent 0133291 commit f954e1c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
24 changes: 18 additions & 6 deletions resources/views/password.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
$suffixIcon = $getSuffixIcon();
$suffixLabel = $getSuffixLabel();
$statePath = $getStatePath();
$isClearText = ! $extraAlpineAttributes['show'];
$stylecode = '';
$x = 0;
Expand All @@ -26,13 +25,26 @@
$stylecode = 'isRtl ? \'padding-left: '.$x.'rem\' : \'padding-right: '.$x.'rem\'';
}
$generatePassword = 'let chars = \''. $getPasswChars().'\';
let password = \'\';
for (let i = 0; i < '. $getPasswLength() . '; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
$generatePassword = '
let chars = \''. $getPasswChars().'\';
let minLen = '. $getPasswLength(). ';
let password = [];
while(password.length <= minLen){
password.push(chars.charAt(Math.floor(Math.random() * 26)));
password.push(chars.charAt(Math.floor(Math.random() * 26) +26));
if(chars.length > 52 && password.length > 4){
password.push(chars.charAt(Math.floor(Math.random() * 10) +52));
}
if(chars.length > 62 && password.length > 4){
password.push(chars.charAt(Math.floor(Math.random() * 10) +62));
}
}
password = password.slice(0, minLen).sort(() => Math.random() - 0.5).join(\'\')
$wire.set(\'' . $getStatePath() . '\', password);
;';
';
if($shouldNotifyOnGenerate()){
$generatePassword .= 'new FilamentNotification()
.title(\'' . $getGenerateText() . '\')
Expand Down
21 changes: 0 additions & 21 deletions src/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ class Password extends TextInput
use CanCopy;
use CanGenerate;

protected array $extraAlpineAttributes = [
['show' => false]
];

protected string $view = 'filament-password-reveal::password';

protected string $showIcon = 'heroicon-o-eye';
Expand All @@ -27,24 +23,7 @@ class Password extends TextInput

protected bool|Closure $initiallyHidden = true;

public ?bool $revealPassword = null;

public function getIsRevealed(): bool
{
if ($this->isRevealable() === false) {
return false;
}
if ($this->revealPassword === null) {
$this->revealPassword = ! $this->isInitiallyHidden();
}

return $this->revealPassword;
}

public function toggleReveal(): void
{
$this->revealPassword = ! $this->revealPassword;
}

public function revealable(bool|Closure $condition = true): static
{
Expand Down
3 changes: 2 additions & 1 deletion src/Traits/CanGenerate.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public function getGenerateText(): string
return $this->evaluate($this->generateText ?? __('Password generated'));
}

public function shouldNotifyOnGenerate(): bool {
public function shouldNotifyOnGenerate(): bool
{
return $this->evaluate($this->notifyOnGenerate);
}
}

0 comments on commit f954e1c

Please sign in to comment.