forked from paragonie/halite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PasswordTest.php
52 lines (44 loc) · 1.26 KB
/
PasswordTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
declare(strict_types=1);
use ParagonIE\Halite\HiddenString;
use ParagonIE\Halite\Password;
use ParagonIE\Halite\Symmetric\EncryptionKey;
/**
* @backupGlobals disabled
* @backupStaticAttributes disabled
*/
class PasswordTest extends PHPUnit_Framework_TestCase
{
public function testEncrypt()
{
$key = new EncryptionKey(new HiddenString(\str_repeat('A', 32)));
$hash = Password::hash(new HiddenString('test password'), $key);
$this->assertTrue(\is_string($hash->getString()));
$this->assertTrue(
Password::verify(
new HiddenString('test password'),
$hash,
$key
)
);
$this->assertFalse(
Password::verify(
new HiddenString('wrong password'),
$hash,
$key
)
);
}
public function testRehash()
{
$key = new EncryptionKey(new HiddenString(\str_repeat('A', 32)));
$hash = Password::hash(new HiddenString('test password'), $key);
$this->assertTrue(\is_string($hash->getString()));
$this->assertFalse(
Password::needsRehash(
$hash,
$key
)
);
}
}