| 1 | <?php |
||
| 7 | class UserEncoder |
||
| 8 | { |
||
| 9 | const HASH_DELIMITER = ':'; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * @var string |
||
| 13 | */ |
||
| 14 | protected $secret; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @param string $secret |
||
| 18 | */ |
||
| 19 | 8 | public function __construct($secret) |
|
| 23 | |||
| 24 | /** |
||
| 25 | * @param string $hash |
||
| 26 | * |
||
| 27 | * @return array |
||
| 28 | */ |
||
| 29 | 2 | public function decodeHash($hash) |
|
| 33 | |||
| 34 | /** |
||
| 35 | * @param array $parts |
||
| 36 | * |
||
| 37 | * @return string |
||
| 38 | */ |
||
| 39 | 4 | public function encodeHash(array $parts) |
|
| 40 | { |
||
| 41 | 4 | return base64_encode(implode(self::HASH_DELIMITER, $parts)); |
|
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param string $username |
||
| 46 | * @param string $password |
||
| 47 | * |
||
| 48 | * @return string |
||
| 49 | */ |
||
| 50 | 4 | public function generateHash($username, $password) |
|
| 54 | |||
| 55 | /** |
||
| 56 | * @see StringUtils::equals |
||
| 57 | */ |
||
| 58 | 2 | public function compareHashes($hash1, $hash2) |
|
| 62 | |||
| 63 | /** |
||
| 64 | * @param string $username |
||
| 65 | * @param string $password |
||
| 66 | * |
||
| 67 | * @return string |
||
| 68 | */ |
||
| 69 | 2 | public function generateTokenValue($username, $password) |
|
| 76 | } |
||
| 77 |