@@ -8,30 +8,30 @@ |
||
8 | 8 | |
9 | 9 | class PBKDF2Test extends SapphireTest |
10 | 10 | { |
11 | - public function testGetIterations() |
|
12 | - { |
|
13 | - $encryptor = new PBKDF2('sha512', 12345); |
|
14 | - $this->assertSame(12345, $encryptor->getIterations()); |
|
15 | - } |
|
11 | + public function testGetIterations() |
|
12 | + { |
|
13 | + $encryptor = new PBKDF2('sha512', 12345); |
|
14 | + $this->assertSame(12345, $encryptor->getIterations()); |
|
15 | + } |
|
16 | 16 | |
17 | - public function testEncrypt() |
|
18 | - { |
|
19 | - $encryptor = new PBKDF2('sha512'); |
|
20 | - $salt = 'predictablesaltforunittesting'; |
|
21 | - $result = $encryptor->encrypt('opensesame', $salt); |
|
22 | - $this->assertSame( |
|
23 | - '6bafcacb90', |
|
24 | - substr($result, 0, 10), |
|
25 | - 'Hashed password with predictable salt did not match fixtured expectation' |
|
26 | - ); |
|
27 | - } |
|
17 | + public function testEncrypt() |
|
18 | + { |
|
19 | + $encryptor = new PBKDF2('sha512'); |
|
20 | + $salt = 'predictablesaltforunittesting'; |
|
21 | + $result = $encryptor->encrypt('opensesame', $salt); |
|
22 | + $this->assertSame( |
|
23 | + '6bafcacb90', |
|
24 | + substr($result, 0, 10), |
|
25 | + 'Hashed password with predictable salt did not match fixtured expectation' |
|
26 | + ); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @expectedException Exception |
|
31 | - * @expectedExceptionMessage Hash algorithm "foobar" not found |
|
32 | - */ |
|
33 | - public function testThrowsExceptionWhenInvalidAlgorithmIsProvided() |
|
34 | - { |
|
35 | - new PBKDF2('foobar'); |
|
36 | - } |
|
29 | + /** |
|
30 | + * @expectedException Exception |
|
31 | + * @expectedExceptionMessage Hash algorithm "foobar" not found |
|
32 | + */ |
|
33 | + public function testThrowsExceptionWhenInvalidAlgorithmIsProvided() |
|
34 | + { |
|
35 | + new PBKDF2('foobar'); |
|
36 | + } |
|
37 | 37 | } |
@@ -11,37 +11,37 @@ |
||
11 | 11 | */ |
12 | 12 | class PBKDF2 extends PasswordEncryptor_PHPHash |
13 | 13 | { |
14 | - /** |
|
15 | - * The number of internal iterations for hash_pbkdf2() to perform for the derivation. |
|
16 | - * |
|
17 | - * @var int |
|
18 | - */ |
|
19 | - protected $iterations = 10000; |
|
14 | + /** |
|
15 | + * The number of internal iterations for hash_pbkdf2() to perform for the derivation. |
|
16 | + * |
|
17 | + * @var int |
|
18 | + */ |
|
19 | + protected $iterations = 10000; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @param string $algorithm |
|
23 | - * @param int|null $iterations |
|
24 | - * @throws Exception If the provided algorithm is not available in the current environment |
|
25 | - */ |
|
26 | - public function __construct(string $algorithm, int $iterations = null) |
|
27 | - { |
|
28 | - parent::__construct($algorithm); |
|
21 | + /** |
|
22 | + * @param string $algorithm |
|
23 | + * @param int|null $iterations |
|
24 | + * @throws Exception If the provided algorithm is not available in the current environment |
|
25 | + */ |
|
26 | + public function __construct(string $algorithm, int $iterations = null) |
|
27 | + { |
|
28 | + parent::__construct($algorithm); |
|
29 | 29 | |
30 | - if ($iterations !== null) { |
|
31 | - $this->iterations = $iterations; |
|
32 | - } |
|
33 | - } |
|
30 | + if ($iterations !== null) { |
|
31 | + $this->iterations = $iterations; |
|
32 | + } |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @return int |
|
37 | - */ |
|
38 | - public function getIterations(): int |
|
39 | - { |
|
40 | - return $this->iterations; |
|
41 | - } |
|
35 | + /** |
|
36 | + * @return int |
|
37 | + */ |
|
38 | + public function getIterations(): int |
|
39 | + { |
|
40 | + return $this->iterations; |
|
41 | + } |
|
42 | 42 | |
43 | - public function encrypt($password, $salt = null, $member = null) |
|
44 | - { |
|
45 | - return hash_pbkdf2($this->getAlgorithm(), $password, $salt, $this->getIterations()); |
|
46 | - } |
|
43 | + public function encrypt($password, $salt = null, $member = null) |
|
44 | + { |
|
45 | + return hash_pbkdf2($this->getAlgorithm(), $password, $salt, $this->getIterations()); |
|
46 | + } |
|
47 | 47 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | { |
28 | 28 | parent::__construct($algorithm); |
29 | 29 | |
30 | - if ($iterations !== null) { |
|
30 | + if ($iterations!==null) { |
|
31 | 31 | $this->iterations = $iterations; |
32 | 32 | } |
33 | 33 | } |