* @license http://www.gnu.org/licenses/lgpl-2.1.html LGPL v 2.1 */ namespace CryptLibExamples\Password; //We first load the bootstrap file so we have access to the library require_once dirname(dirname(__DIR__)) . '/lib/CryptLib/bootstrap.php'; /** * Now, let's create a password that's compatible with Drupal */ // First, let's create an instance of Drupal, where 15 is the iteration count for D7 $hasher = new \CryptLib\Password\Implementation\Drupal(15); $password = '******'; // Now, let's create a password hash of the password "FooBarBaz" $hash = $hasher->create($password); //It's safe to print, so let's output it: printf("Password: %s\nHash: %s\n\n", $password, $hash); /** * Now, we can also verify any passwords created by Drupal. First, let's load a hash. * * This works, because it detects the iteration count that's stored in the hash, and * pre-configures our instance for us. */ $hasher2 = \CryptLib\Password\Implementation\Drupal::loadFromHash($hash); /** * Next, we verify the hash with the expected password. */ $test = $hasher2->verify($password, $hash); /** * $test should now contain a boolean value as to the validity of the hash */ printf("Verification was %s\n\n", $test ? "Successful!" : "Failed!");
/** * @covers CryptLib\Password\Implementation\Drupal::verify * @dataProvider provideTestVerify * @group Vectors */ public function testVerify($pass, $expect, $value) { $apr = new Drupal(); $this->assertEquals($value, $apr->verify($pass, $expect)); }
/** * @covers CryptLib\Password\Implementation\Drupal */ public function testCreateAndVerify() { $hash = new Drupal(10); $test = $hash->create('Foobar'); $this->assertTrue($hash->verify('Foobar', $test)); }