Skip to content

Commit

Permalink
Add password element
Browse files Browse the repository at this point in the history
  • Loading branch information
lippserd committed Oct 24, 2022
1 parent 288a489 commit 5932e71
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions src/FormElement/PasswordElement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace ipl\Html\FormElement;

class PasswordElement extends InputElement
{
protected const OBSCURE_PASSWORD = '_ipl_form_5847ed1b5b8ca';

protected $password;

protected $type = 'password';

public function getValue()
{
return $this->password;
}

public function setValue($value)
{
parent::setValue($value);
// Consider any changes to the password made by the parent setValue() call.
$value = parent::getValue();

if ($value !== static::OBSCURE_PASSWORD) {
$this->password = $value;
}

return $this;
}

public function getValueAttribute()
{
return $this->hasValue() ? static::OBSCURE_PASSWORD : null;
}
}
2 changes: 1 addition & 1 deletion tests/TestDummy/ObscurePassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class ObscurePassword extends PasswordElement
{
public static function get(): string
{
return static::DUMMYPASSWORD;
return static::OBSCURE_PASSWORD;
}
}

0 comments on commit 5932e71

Please sign in to comment.