<?php require __DIR__ . '/vendor/autoload.php'; use mindplay\blowfish\BlowfishService; test('Entropy functions work as expected', function () { $service = new BlowfishService(); $entropy = invoke($service, 'getEntropy', array(10)); ok(strlen($entropy) === 10, 'returns 10 bytes of entropy'); $entropy = invoke($service, 'getEntropy', array(100)); ok(strlen($entropy) === 100, 'returns 100 bytes of entropy'); }); test('Can hash and check passwords', function () { foreach (array(4, 10) as $cost) { $service = new BlowfishService($cost); foreach (array('x', 'p@s$w0Rd', 'KytmCwqjb6wYPGgEHZ55DRfDanNVWwxnmMMnzCRu72ghQ89S') as $password) { $hash = $service->hash($password); ok($service->check($password, $hash), 'password verified (with cost ' . $cost . ')', $password); ok($service->check($password . '-', $hash) === false, 'invalid password rejected (with cost ' . $cost . ')', $password); ok($service->check($password, $hash . '-') === false, 'invalid hash rejected (with cost ' . $cost . ')', $password); } } }); exit(status()); // https://gist.github.com/mindplay-dk/4260582 /** * @param string $name test description * @param callable $function test implementation */ function test($name, $function) { echo "\n=== {$name} ===\n\n";