| 1 | <?php |
||
| 7 | class EmailIdentity extends Identity |
||
| 8 | { |
||
| 9 | |||
| 10 | const HASH_ALGO = PASSWORD_BCRYPT; |
||
| 11 | const HASH_COST = 12; |
||
| 12 | |||
| 13 | private $emailAddress; |
||
| 14 | private $password; |
||
| 15 | private $hash; |
||
| 16 | |||
| 17 | protected $type = Identity::TYPE_EMAIL; |
||
| 18 | |||
| 19 | |||
| 20 | 2 | public function setEmailAddress($emailAddress) |
|
| 24 | |||
| 25 | |||
| 26 | /** |
||
| 27 | * @codeCoverageIgnore |
||
| 28 | */ |
||
| 29 | public function getEmailAddress() |
||
| 33 | |||
| 34 | |||
| 35 | 1 | public function getFingerprint(): string |
|
| 39 | |||
| 40 | |||
| 41 | 1 | public function setPassword($password, $cost = self::HASH_COST) |
|
| 42 | { |
||
| 43 | 1 | $this->password = (string) $password; |
|
| 44 | 1 | $this->hash = $this->createHash($password, $cost); |
|
| 45 | 1 | } |
|
| 46 | |||
| 47 | |||
| 48 | /** |
||
| 49 | * @codeCoverageIgnore |
||
| 50 | */ |
||
| 51 | public function getHash() |
||
| 55 | |||
| 56 | |||
| 57 | 1 | private function createHash($password, int $cost): string |
|
| 58 | { |
||
| 59 | 1 | return password_hash($password, self::HASH_ALGO, ['cost' => $cost]); |
|
| 60 | } |
||
| 61 | |||
| 62 | |||
| 63 | 3 | public function setHash($hash) |
|
| 71 | |||
| 72 | |||
| 73 | 1 | public function matchPassword($password): bool |
|
| 77 | |||
| 78 | |||
| 79 | 1 | public function hasOldHash($cost = self::HASH_COST): bool |
|
| 83 | } |
||
| 84 |