mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 22:21:42 +00:00
Use Guzzle, not Requests library.
This commit is contained in:
@@ -23,8 +23,9 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Services\Password;
|
||||
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Log;
|
||||
use Requests;
|
||||
|
||||
/**
|
||||
* Class PwndVerifierV2.
|
||||
@@ -44,27 +45,30 @@ class PwndVerifierV2 implements Verifier
|
||||
$prefix = substr($hash, 0, 5);
|
||||
$rest = substr($hash, 5);
|
||||
$uri = sprintf('https://api.pwnedpasswords.com/range/%s', $prefix);
|
||||
$opt = ['useragent' => 'Firefly III v' . config('firefly.version'), 'timeout' => 2];
|
||||
$opt = [
|
||||
'headers' => ['User-Agent' => 'Firefly III v' . config('firefly.version')],
|
||||
'timeout' => 2];
|
||||
|
||||
Log::debug(sprintf('hash prefix is %s', $prefix));
|
||||
Log::debug(sprintf('rest is %s', $rest));
|
||||
|
||||
try {
|
||||
$result = Requests::get($uri, $opt);
|
||||
} catch (Exception $e) {
|
||||
$client = new Client();
|
||||
$res = $client->request('GET', $uri, $opt);
|
||||
} catch (GuzzleException|Exception $e) {
|
||||
return true;
|
||||
}
|
||||
Log::debug(sprintf('Status code returned is %d', $result->status_code));
|
||||
if (404 === $result->status_code) {
|
||||
Log::debug(sprintf('Status code returned is %d', $res->getStatusCode()));
|
||||
if (404 === $res->getStatusCode()) {
|
||||
return true;
|
||||
}
|
||||
$strpos = stripos($result->body, $rest);
|
||||
$strpos = stripos($res->getBody()->getContents(), $rest);
|
||||
if ($strpos === false) {
|
||||
Log::debug(sprintf('%s was not found in result body. Return true.', $rest));
|
||||
|
||||
return true;
|
||||
}
|
||||
Log::debug('Could not find %s, return FALSE.');
|
||||
Log::debug(sprintf('Could not find %s, return FALSE.', $rest));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user