protected function updateUserPasswordHash(UserEntity $user, $password, Bcrypt $bcrypt) { $hash = explode('$', $user->getPassword()); if ($hash[2] === $bcrypt->getCost()) { return; } $user = $this->getHydrator()->hydrate(compact('password'), $user); $this->getMapper()->update($user); }
public function testSetCost() { $this->bcrypt->setCost('16'); $this->assertEquals('16', $this->bcrypt->getCost()); }
public function resetPassword(array $credentials) { $username = $credentials['username']; $password = $credentials['password']; $em = $this->getEntityManager()->getRepository($this); $bcrypt = new Bcrypt(); $bcrypt->setCost(14); $hash = explode('$', $userObject->getPassword()); if ($hash[2] === $bcrypt->getCost()) { return; } $userObject->setPassword($bcrypt->create($password)); }
/** * @param UserEntity $userObject * @param $password * @param Bcrypt $bcrypt * @return $this|bool */ protected function updateUserPasswordHash(UserEntity $userObject, $password, Bcrypt $bcrypt) { $hash = explode('$', $userObject->getPassword()); if ($hash[2] === $bcrypt->getCost()) { return true; } $userObject->setPassword($bcrypt->create($password)); $this->getUserMapper()->update($userObject); return $this; }
* @copyright Copyright (c) 2014-2016 Zend Technologies USA Inc. (http://www.zend.com) */ use Zend\Crypt\Password\Bcrypt; $autoload = realpath(__DIR__ . '/../vendor/autoload.php'); if (!$autoload) { // Attempt to locate it relative to the application root $autoload = realpath(__DIR__ . '/../../../autoload.php'); } if (!$autoload) { throw new RuntimeException('Unable to locate autoloader. Please run `composer install`.'); } include $autoload; $help = <<<EOH Usage: php bcrypt.php <password> [cost] Arguments: <password> The user's password [cost] The value of the cost parameter of bcrypt. (default is %d) EOH; $bcrypt = new Bcrypt(); if ($argc < 2) { printf($help, $bcrypt->getCost()); exit(1); } if (isset($argv[2])) { $bcrypt->setCost($argv[2]); } printf("%s\n", $bcrypt->create($argv[1]));