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\Portable;
 15: 
 16: /**
 17:  * PHPass Portable 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 PortableTest 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 ("test1", '$H$9aaaaaSXBjgypwqm.JsMssPLiS8YQ00'),
 37:             array ("123456", '$H$9PE8jEklgZhgLmZl5.HYJAzfGCQtzi1'),
 38:             array ("123456", '$H$9pdx7dbOW3Nnt32sikrjAxYFjX8XoK1'),
 39:             array ("thisisalongertestPW", '$P$912345678LIjjb6PhecupozNBmDndU0'),
 40:             array ("JohnRipper", '$P$612345678si5M0DDyPpmRCmcltU/YW/'),
 41:             array ("JohnRipper", '$H$712345678WhEyvy1YWzT4647jzeOmo0'),
 42:             array ("JohnRipper", '$P$B12345678L6Lpt4BxNotVIMILOa9u81'),
 43:         );
 44: 
 45:         return $vectors;
 46:     }
 47: 
 48:     /**
 49:      * Provide invalid test vectors.
 50:      *
 51:      * @return array
 52:      */
 53:     public function invalidTestVectorProvider()
 54:     {
 55:         $vectors = array (
 56:             array ("", '*0', '*1'),
 57:             array ("", '*1', '*0'),
 58:         );
 59: 
 60:         return $vectors;
 61:     }
 62: 
 63:     /**
 64:      * Verify that the class produces correct results with valid test vectors.
 65:      *
 66:      * @test
 67:      * @dataProvider validTestVectorProvider
 68:      * @param string $password
 69:      * @param string $hash
 70:      */
 71:     public function validTestVectorsProduceExpectedResults($password, $hash)
 72:     {
 73:         $config = substr($hash, 0, 12);
 74:         $this->assertEquals($hash, Portable::hash($password, $config));
 75:         $this->assertTrue(Portable::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:         $config = substr($hash, 0, 12);
 89:         $this->assertEquals($errorString, Portable::hash($password, $config));
 90:         $this->assertFalse(Portable::verify($password, $hash));
 91:     }
 92: 
 93:     /**
 94:      * @test
 95:      */
 96:     public function genconfigAndParseconfigProduceMatchingResults()
 97:     {
 98:         $options = array (
 99:             'ident' => 'H',
100:             'rounds' => 15,
101:             'salt' => 'CCCCCCC.',
102:         );
103:         $config = Portable::genConfig($options);
104: 
105:         $this->assertEquals('$H$DCCCCCCC.', $config, $config);
106:         $this->assertSame($options, Portable::parseConfig($config));
107:     }
108: 
109: }
110: 
PHP Password Library API documentation generated by ApiGen 2.8.0