@@ -6,6 +6,6 @@ |
||
6 | 6 | */ |
7 | 7 | |
8 | 8 | define("ROOT", __DIR__); |
9 | -define("SRC", __DIR__ . '/Src'); |
|
9 | +define("SRC", __DIR__.'/Src'); |
|
10 | 10 | |
11 | 11 | require_once './vendor/autoload.php'; |
@@ -83,28 +83,28 @@ |
||
83 | 83 | public function truePasswordProvider() |
84 | 84 | { |
85 | 85 | return array( |
86 | - ['password',\password_hash('password', PASSWORD_DEFAULT)], |
|
87 | - ['foobar',\password_hash('foobar', PASSWORD_DEFAULT)], |
|
88 | - ['234234234cookie',\password_hash('234234234cookie', PASSWORD_DEFAULT)], |
|
89 | - ['fobatraz56278',\password_hash('fobatraz56278', PASSWORD_DEFAULT)], |
|
90 | - ['foo__fgg__bat__789',\password_hash('foo__fgg__bat__789', PASSWORD_DEFAULT)], |
|
91 | - ['passwdsasdads2123ord',\password_hash('passwdsasdads2123ord', PASSWORD_DEFAULT)] |
|
86 | + ['password', \password_hash('password', PASSWORD_DEFAULT)], |
|
87 | + ['foobar', \password_hash('foobar', PASSWORD_DEFAULT)], |
|
88 | + ['234234234cookie', \password_hash('234234234cookie', PASSWORD_DEFAULT)], |
|
89 | + ['fobatraz56278', \password_hash('fobatraz56278', PASSWORD_DEFAULT)], |
|
90 | + ['foo__fgg__bat__789', \password_hash('foo__fgg__bat__789', PASSWORD_DEFAULT)], |
|
91 | + ['passwdsasdads2123ord', \password_hash('passwdsasdads2123ord', PASSWORD_DEFAULT)] |
|
92 | 92 | ); |
93 | 93 | } |
94 | 94 | |
95 | 95 | public function falsePasswordProvider() |
96 | 96 | { |
97 | 97 | return array( |
98 | - ['password','$2y$10$rUHpBM6hi0TyCBIgGnJYAuBPLe66sadkE.RW'], |
|
99 | - ['password','cGFzc3dvcmQ='], |
|
100 | - ['password','5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'], |
|
101 | - ['password','5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8'], |
|
102 | - ['password','74dfc2b27acfa364da55f93a5caee29ccad3557247eda238831b3e9bd931b01d77fe994e4f12b9d4cfa92a124461d2065197d8cf7f33fc88566da2db2a4d6eae'], |
|
103 | - ['password','db4d9992897eda89b50f1d3208db607902da7e79c6f3bc6e6933cc5919068564'], |
|
104 | - ['password','35c246d5'], |
|
105 | - ['password','ycbTFtbcTZUqeJ/UuIWO1w=='], |
|
106 | - ['password','c9c6d316d6dc4d952a789fd4b8858ed7'], |
|
107 | - ['password','c9:c6:d3:16:d6:dc:4d:95:2a:78:9f:d4:b8:85:8e:d7'], |
|
98 | + ['password', '$2y$10$rUHpBM6hi0TyCBIgGnJYAuBPLe66sadkE.RW'], |
|
99 | + ['password', 'cGFzc3dvcmQ='], |
|
100 | + ['password', '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'], |
|
101 | + ['password', '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8'], |
|
102 | + ['password', '74dfc2b27acfa364da55f93a5caee29ccad3557247eda238831b3e9bd931b01d77fe994e4f12b9d4cfa92a124461d2065197d8cf7f33fc88566da2db2a4d6eae'], |
|
103 | + ['password', 'db4d9992897eda89b50f1d3208db607902da7e79c6f3bc6e6933cc5919068564'], |
|
104 | + ['password', '35c246d5'], |
|
105 | + ['password', 'ycbTFtbcTZUqeJ/UuIWO1w=='], |
|
106 | + ['password', 'c9c6d316d6dc4d952a789fd4b8858ed7'], |
|
107 | + ['password', 'c9:c6:d3:16:d6:dc:4d:95:2a:78:9f:d4:b8:85:8e:d7'], |
|
108 | 108 | ); |
109 | 109 | } |
110 | 110 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | ); |
73 | 73 | } |
74 | 74 | |
75 | - public function getEncodedHash(array $payload = []){ |
|
75 | + public function getEncodedHash(array $payload = []) { |
|
76 | 76 | $hash = $this->createHash($this->algorithm, $payload); |
77 | 77 | return base64_encode($this->algorithm.'='.$hash); |
78 | 78 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | { |
91 | 91 | $decodedHash = base64_decode($encodedHash); |
92 | 92 | |
93 | - list($algo, $hash) = array_pad( explode('=', $decodedHash), 4, $this->algorithm); |
|
93 | + list($algo, $hash) = array_pad(explode('=', $decodedHash), 4, $this->algorithm); |
|
94 | 94 | $payloadHash = $this->createHash($this->algorithm, $payload, $this->privateKey); |
95 | 95 | |
96 | 96 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | } |
129 | 129 | |
130 | 130 | |
131 | - public function getPayload(){ |
|
131 | + public function getPayload() { |
|
132 | 132 | return $this->payload; |
133 | 133 | } |
134 | 134 |
@@ -60,7 +60,8 @@ discard block |
||
60 | 60 | /** |
61 | 61 | * Creates hash from payload. |
62 | 62 | * @param array $payload |
63 | - * @return mixed |
|
63 | + * @param string $algorithm |
|
64 | + * @return string |
|
64 | 65 | */ |
65 | 66 | public function create($algorithm, array $payload = [], $privateKey) |
66 | 67 | { |
@@ -83,7 +84,7 @@ discard block |
||
83 | 84 | /** |
84 | 85 | * Compare received hash against payload. |
85 | 86 | * |
86 | - * @param $encodedHash |
|
87 | + * @param string $encodedHash |
|
87 | 88 | * @param array $payload |
88 | 89 | * @return bool |
89 | 90 | * @throws \Exception |
@@ -108,7 +109,7 @@ discard block |
||
108 | 109 | |
109 | 110 | |
110 | 111 | /** |
111 | - * @param $key |
|
112 | + * @param string $key |
|
112 | 113 | * @return $this |
113 | 114 | */ |
114 | 115 | public function setPrivateKey($key) |
@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | $this->data = ['foo' => 'bar']; |
33 | 33 | $this->privateKey = 'privateKey'; |
34 | 34 | |
35 | - $this->hmac = new HashHmac($this->privateKey,$this->algo); |
|
35 | + $this->hmac = new HashHmac($this->privateKey, $this->algo); |
|
36 | 36 | |
37 | 37 | } |
38 | 38 | |
39 | 39 | public function testHash() |
40 | 40 | { |
41 | 41 | $actual = $this->hmac->create($this->algo, $this->data, $this->privateKey); |
42 | - $expected = hash_hmac($this->algo, json_decode($this->data) , $this->privateKey); |
|
42 | + $expected = hash_hmac($this->algo, json_decode($this->data), $this->privateKey); |
|
43 | 43 | $result = $this->hmac->verify($actual, $expected); |
44 | 44 | $this->assertEquals(true, $result); |
45 | 45 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | public function testCompareHash() |
48 | 48 | { |
49 | 49 | $encodedHash = $this->hmac->getEncodedHash($this->data); |
50 | - $this->assertEquals(true, $this->auth->compareHash($encodedHash,$this->data)); |
|
50 | + $this->assertEquals(true, $this->auth->compareHash($encodedHash, $this->data)); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | public function testCompareHashInvalidAlgo() |