1 | <?php namespace SimpleHash\Calculator; |
||
13 | class BcryptCalculator implements HashCalculatorInterface |
||
14 | { |
||
15 | const DEFAULT_COST = '10'; |
||
16 | const DEFAULT_SALT = 'Af13GgKoL503sCvf42dJ18'; |
||
17 | |||
18 | /** |
||
19 | * Costs |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | private $cost = ''; |
||
24 | |||
25 | /** |
||
26 | * Salt |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | private $salt = ''; |
||
31 | |||
32 | /** |
||
33 | * Constructor |
||
34 | * |
||
35 | * @param array $params |
||
36 | */ |
||
37 | 4 | public function __construct(array $params = array()) |
|
42 | |||
43 | /** |
||
44 | * Returns the Bcrypt hash |
||
45 | * |
||
46 | * @param string $data |
||
47 | * @return string |
||
48 | */ |
||
49 | 3 | public function getHash($data) |
|
53 | |||
54 | /** |
||
55 | * Builds the final salt string for PHP crypt. |
||
56 | * The blowfish type "$2y$" is used. |
||
57 | * |
||
58 | * @return string |
||
59 | */ |
||
60 | 3 | private function buildSaltString() |
|
64 | |||
65 | /** |
||
66 | * Sets the salt string from parameter array. |
||
67 | * If no salt is given, the default value will be used! |
||
68 | * |
||
69 | * @return void |
||
70 | */ |
||
71 | 4 | private function setSaltFromParams(array $params) |
|
76 | |||
77 | /** |
||
78 | * Sets the cost string from parameter array. |
||
79 | * If no cost is given, the default value will be used! |
||
80 | * |
||
81 | * @return void |
||
82 | */ |
||
83 | 4 | private function setCostFromParams(array $params) |
|
88 | |||
89 | /** |
||
90 | * Returns the first match from parameter array |
||
91 | * |
||
92 | * @param array $params |
||
93 | * @param string $regex |
||
94 | * @return string |
||
95 | */ |
||
96 | 4 | private function getMatchingData(array $params, $regex) |
|
106 | } |
||
107 |