| Total Complexity | 7 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 5 | class Password |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @var string |
||
| 9 | */ |
||
| 10 | private $value; |
||
| 11 | |||
| 12 | private function __construct() |
||
| 13 | { |
||
| 14 | } |
||
| 15 | |||
| 16 | public static function fromHash(string $hash) |
||
| 17 | { |
||
| 18 | $password = new Password(); |
||
| 19 | $password->setValue($hash); |
||
| 20 | |||
| 21 | return $password; |
||
| 22 | } |
||
| 23 | |||
| 24 | public static function fromPlainText(string $plainTextValue) |
||
| 25 | { |
||
| 26 | if (!preg_match('/^(?=[^ ])(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z])(.{8,})(?<=\S)$/', $plainTextValue)) { |
||
| 27 | throw new \InvalidArgumentException( |
||
| 28 | 'Invalid value for password. '. |
||
| 29 | 'Must be at least 8 characters long, contain at least one lowercase, '. |
||
| 30 | 'one uppercase and one non-alphabetical character and must not start or end with a space.' |
||
| 31 | ); |
||
| 32 | } |
||
| 33 | |||
| 34 | $password = new Password(); |
||
| 35 | $password->setValue(password_hash($plainTextValue, PASSWORD_DEFAULT)); |
||
| 36 | |||
| 37 | return $password; |
||
| 38 | } |
||
| 39 | |||
| 40 | private function setValue(string $value) |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @return string |
||
| 47 | */ |
||
| 48 | public function toNative(): string |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param string $plainTextValue |
||
| 55 | * @return bool |
||
| 56 | */ |
||
| 57 | public function verifies(string $plainTextValue): bool |
||
| 60 | } |
||
| 61 | } |
||
| 62 |