Skip to content

Commit 5932e71

Browse files
committed
Add password element
1 parent 288a489 commit 5932e71

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace ipl\Html\FormElement;
4+
5+
class PasswordElement extends InputElement
6+
{
7+
protected const OBSCURE_PASSWORD = '_ipl_form_5847ed1b5b8ca';
8+
9+
protected $password;
10+
11+
protected $type = 'password';
12+
13+
public function getValue()
14+
{
15+
return $this->password;
16+
}
17+
18+
public function setValue($value)
19+
{
20+
parent::setValue($value);
21+
// Consider any changes to the password made by the parent setValue() call.
22+
$value = parent::getValue();
23+
24+
if ($value !== static::OBSCURE_PASSWORD) {
25+
$this->password = $value;
26+
}
27+
28+
return $this;
29+
}
30+
31+
public function getValueAttribute()
32+
{
33+
return $this->hasValue() ? static::OBSCURE_PASSWORD : null;
34+
}
35+
}

tests/TestDummy/ObscurePassword.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ class ObscurePassword extends PasswordElement
88
{
99
public static function get(): string
1010
{
11-
return static::DUMMYPASSWORD;
11+
return static::OBSCURE_PASSWORD;
1212
}
1313
}

0 commit comments

Comments
 (0)