'verifyPassword' ); } public function verifyPassword($password) { $hash = strtoupper(sha1($password)); $prefix = substr($hash, 0, 5); $suffix = substr($hash, 5); $url = 'https://api.pwnedpasswords.com/range/' . $prefix; try { $response = Http::sendHttpRequest($url, $timeout = 10); } catch (\Exception $e) { $logger = StaticContainer::getContainer()->get('Psr\Log\LoggerInterface'); $logger->warning("Can't reach haveibeenpwned.com"); $logger->warning($e->getMessage()); throw new Exception(Piwik::translate("PasswordVerifier_CantReachAPI")); } $hashes = []; if (strpos($response, $suffix) === false) { return true; } foreach (explode("\n", $response) as $hash) { $split = explode(":", $hash); $hashes[$split[0]] = (int)$split[1]; } if (empty($hashes[$suffix])) { return true; } throw new \Exception(Piwik::translate('PasswordVerifier_PasswordFoundInDb', $hashes[$suffix])); } }