1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace PHPassLib\Test\Hash;
13:
14: use PHPassLib\Hash\SHA1Crypt;
15:
16: 17: 18: 19: 20: 21: 22: 23:
24: class SHA1CryptTest extends \PHPUnit_Framework_TestCase
25: {
26:
27: 28: 29: 30: 31:
32: public function validTestVectorProvider()
33: {
34: $vectors = array (
35: array ("password", '$sha1$40000$jtNX3nZ2$hBNaIXkt4wBI2o5rsi8KejSjNqIq'),
36: array ("password", '$sha1$19703$iVdJqfSE$v4qYKl1zqYThwpjJAoKX6UvlHq/a'),
37: array ("password", '$sha1$21773$uV7PTeux$I9oHnvwPZHMO0Nq6/WgyGV/tDJIH'),
38: array ("test", '$sha1$1$Wq3GL2Vp$C8U25GvfHS8qGHimExLaiSFlGkAe'),
39: );
40:
41: return $vectors;
42: }
43:
44: 45: 46: 47: 48:
49: public function invalidTestVectorProvider()
50: {
51: $vectors = array (
52: array ("", '*0', '*1'),
53: array ("", '*1', '*0'),
54: );
55:
56: return $vectors;
57: }
58:
59: 60: 61: 62: 63: 64: 65: 66:
67: public function validTestVectorsProduceExpectedResults($password, $hash)
68: {
69: $this->assertEquals($hash, SHA1Crypt::hash($password, $hash));
70: $this->assertTrue(SHA1Crypt::verify($password, $hash));
71: }
72:
73: 74: 75: 76: 77: 78: 79: 80:
81: public function invalidTestVectorsProduceExpectedResults($password, $hash, $errorString)
82: {
83: $this->assertEquals($errorString, SHA1Crypt::hash($password, $hash));
84: $this->assertFalse(SHA1Crypt::verify($password, $hash));
85: }
86:
87: 88: 89:
90: public function genconfigAndParseconfigProduceMatchingResults()
91: {
92: $options = array (
93: 'rounds' => 5000,
94: 'salt' => 'CCCCCCC.',
95: );
96: $config = SHA1Crypt::genConfig($options);
97:
98: $this->assertEquals('$sha1$5000$CCCCCCC.', $config);
99: $this->assertSame($options, SHA1Crypt::parseConfig($config));
100: }
101:
102: }
103: