Skip to content

Commit

Permalink
fixed random hex generation
Browse files Browse the repository at this point in the history
  • Loading branch information
simialbi committed Feb 15, 2023
1 parent 2546b3f commit 442ede3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/components/Captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Yii;
use yii\base\Component;
use yii\base\Exception;
use yii\base\InvalidArgumentException;
use yii\helpers\ArrayHelper;

/**
Expand Down Expand Up @@ -373,7 +374,7 @@ private function utilRandomHex(int $count): string
{
try {
$bytes = Yii::$app->security->generateRandomKey($count);
} catch (Exception $e) {
} catch (Exception|InvalidArgumentException $e) {
$bytes = openssl_random_pseudo_bytes($count);
}

Expand Down Expand Up @@ -517,7 +518,7 @@ public function getImage(string $filePath): string
}

// Add some noise randomly, so images can't be saved and matched easily by filesize or checksum
$img .= $this->utilRandomHex(rand(0, 1500));
$img .= $this->utilRandomHex(rand(1, 1500));

return $img;
}
Expand Down

0 comments on commit 442ede3

Please sign in to comment.