1 | <?php |
||
17 | class Password implements ValidatorInterface |
||
18 | { |
||
19 | /** |
||
20 | * pattern for password |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | |||
25 | protected $_pattern = '^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])\S{10,100}$'; |
||
26 | |||
27 | /** |
||
28 | * get the pattern |
||
29 | * |
||
30 | * @since 4.3.0 |
||
31 | * |
||
32 | * @return string |
||
33 | */ |
||
34 | |||
35 | 1 | public function getPattern() : string |
|
39 | |||
40 | /** |
||
41 | * validate the password |
||
42 | * |
||
43 | * @since 4.3.0 |
||
44 | * |
||
45 | * @param string $password password to be validated |
||
46 | * |
||
47 | * @return bool |
||
48 | */ |
||
49 | |||
50 | 10 | public function validate(string $password = null) : bool |
|
51 | { |
||
52 | 10 | return preg_match('/' . $this->_pattern . '/', $password); |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * match password hash |
||
57 | * |
||
58 | * @since 4.3.0 |
||
59 | * |
||
60 | * @param string $password password to be validated |
||
61 | * @param string $hash hash to be validated |
||
62 | * |
||
63 | * @return bool |
||
64 | */ |
||
65 | |||
66 | 4 | public function matchHash(string $password = null, string $hash = null) : bool |
|
71 | } |
||
72 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: