1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace PHPassLib\Test\Hash;
13:
14: use PHPassLib\Hash\MD5Crypt;
15:
16: 17: 18: 19: 20: 21: 22: 23:
24: class MD5CryptTest extends \PHPUnit_Framework_TestCase
25: {
26:
27: 28: 29: 30: 31:
32: public function validTestVectorProvider()
33: {
34: $vectors = array (
35:
36: array ("0123456789ABCDE", '$1$12345678$aIccj83HRDBo6ux1bVx7D1'),
37: array ("12345678", '$1$12345678$f8QoJuo0DpBRfQSD0vglc1'),
38: array ("", '$1$$qRPK7m23GJusamGpoGLby/'),
39: array ("no salt", '$1$$AuJCr07mI7DSew03TmBIv/'),
40: array ("", '$1$12345678$xek.CpjQUVgdf/P2N9KQf/'),
41: array ("1234", '$1$1234$BdIMOAWFOV2AQlLsrN/Sw.'),
42: );
43:
44: return $vectors;
45: }
46:
47: 48: 49: 50: 51:
52: public function invalidTestVectorProvider()
53: {
54:
55: $vectors = array (
56: array ("invalid salt", '$1$`!@#%^&*$E6hD76/pKTS8qToBCkux30', '*0'),
57: array ("", '*0', '*1'),
58: array ("", '*1', '*0'),
59: );
60:
61: return $vectors;
62: }
63:
64: 65: 66: 67: 68: 69: 70: 71:
72: public function validTestVectorsProduceExpectedResults($password, $hash)
73: {
74: $this->assertEquals($hash, MD5Crypt::hash($password, $hash));
75: $this->assertTrue(MD5Crypt::verify($password, $hash));
76: }
77:
78: 79: 80: 81: 82: 83: 84: 85:
86: public function invalidTestVectorsProduceExpectedResults($password, $hash, $errorString)
87: {
88: $this->assertEquals($errorString, MD5Crypt::hash($password, $hash));
89: $this->assertFalse(MD5Crypt::verify($password, $hash));
90: }
91:
92: 93: 94:
95: public function genconfigAndParseconfigProduceMatchingResults()
96: {
97: $options = array (
98: 'salt' => 'CCCCC.',
99: );
100: $config = MD5Crypt::genConfig($options);
101:
102: $this->assertEquals('$1$CCCCC.', $config);
103: $this->assertSame($options, MD5Crypt::parseConfig($config));
104: }
105:
106: }
107: