Overview

Namespaces

  • PHP
  • PHPassLib
    • Application
    • Exception
    • Hash
    • Test
      • Application
      • Hash

Classes

  • BCryptTest
  • BSDiCryptTest
  • DESCryptTest
  • MD5CryptTest
  • PBKDF2Test
  • PortableTest
  • SHA1CryptTest
  • SHA256CryptTest
  • SHA512CryptTest
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * PHP Password Library
  4:  *
  5:  * @package PHPassLib\Tests
  6:  * @author Ryan Chouinard <rchouinard@gmail.com>
  7:  * @copyright Copyright (c) 2012, Ryan Chouinard
  8:  * @license MIT License - http://www.opensource.org/licenses/mit-license.php
  9:  * @version 3.0.0-dev
 10:  */
 11: 
 12: namespace PHPassLib\Test\Hash;
 13: 
 14: use PHPassLib\Hash\MD5Crypt;
 15: 
 16: /**
 17:  * MD5 Crypt Module Tests
 18:  *
 19:  * @package PHPassLib\Tests
 20:  * @author Ryan Chouinard <rchouinard@gmail.com>
 21:  * @copyright Copyright (c) 2012, Ryan Chouinard
 22:  * @license MIT License - http://www.opensource.org/licenses/mit-license.php
 23:  */
 24: class MD5CryptTest extends \PHPUnit_Framework_TestCase
 25: {
 26: 
 27:     /**
 28:      * Provide valid test vectors.
 29:      *
 30:      * @return array
 31:      */
 32:     public function validTestVectorProvider()
 33:     {
 34:         $vectors = array (
 35:             // From John the Ripper 1.7.9
 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:      * Provide invalid test vectors.
 49:      *
 50:      * @return array
 51:      */
 52:     public function invalidTestVectorProvider()
 53:     {
 54:         // TODO: Find a good source of test vectors
 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:      * Verify that the class produces correct results with valid test vectors.
 66:      *
 67:      * @test
 68:      * @dataProvider validTestVectorProvider
 69:      * @param string $password
 70:      * @param string $hash
 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:      * Verify that the class produces correct results with invalid test vectors.
 80:      *
 81:      * @test
 82:      * @dataProvider invalidTestVectorProvider
 83:      * @param string $password
 84:      * @param string $hash
 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:      * @test
 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: 
PHP Password Library API documentation generated by ApiGen 2.8.0