/** * @param string $password * @param PasswordHashOptions $oldOptions * @param PasswordHashOptions $newOptions * @param boolean $shouldChange * * @dataProvider recalculateHashIfNecessaryDataProvider */ public function testRecalculateHashIfNecessary($password, $oldOptions, $newOptions, $shouldChange) { $hash = $this->passwordService->calculateHash($password, $oldOptions); $result = $this->passwordService->recalculateHashIfNecessary($password, $newOptions, $hash); if ($shouldChange) { $this->assertNotEquals($hash, $result, "Hash should change but did not!"); } else { $this->assertEquals($hash, $result, "Hash should not change!"); } }
/** * @inheritdoc */ public function readAndVerifyUserFromAuthorizationHeader($authorizationHeaderValue) { Assertion::string($authorizationHeaderValue); if (empty($authorizationHeaderValue)) { return null; } try { $credentials = $this->authorizationHeaderService->parseAuthorizationHeaderString($authorizationHeaderValue); } catch (AHSInvalidAuthorizationHeaderException $e) { throw new InvalidAuthorizationHeaderException($e->getMessage()); } try { $user = $this->userService->getUserByIdentifier($credentials->getUserIdentifier()); } catch (UserDoesNotExistException $e) { throw new InvalidUserException('User not found or password does not match'); } $verified = $this->passwordService->verify($credentials->getPassword(), $user->getPasswordHash()); if (!$verified) { throw new InvalidUserException('User not found or password does not match'); } return $user; }