Skip to content

Commit

Permalink
Laminas\Math abandoned, stop using it
Browse files Browse the repository at this point in the history
  • Loading branch information
voltan committed Dec 16, 2024
1 parent 371e7e0 commit a4a565b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"laminas/laminas-mvc-plugins": "*",
"laminas/laminas-mvc-middleware": "*",
"laminas/laminas-authentication": "*",
"laminas/laminas-math": "*",
"laminas/laminas-http": "*",
"laminas/laminas-eventmanager": "*",
"laminas/laminas-cache": "*",
Expand Down
8 changes: 5 additions & 3 deletions src/Service/AccountService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
namespace Pi\User\Service;

use Fig\Http\Message\StatusCodeInterface;
use Laminas\Math\Rand;
use Pi\Core\Security\Account\AccountLocked;
use Pi\Core\Security\Account\AccountLoginAttempts;
use Pi\Core\Service\CacheService;
use Pi\Core\Service\TranslatorService;
use Pi\Core\Service\UtilityService;
use Pi\Notification\Service\NotificationService;
use Pi\User\Repository\AccountRepositoryInterface;
use Random\RandomException;
use RobThree\Auth\Algorithm;
use RobThree\Auth\Providers\Qr\EndroidQrCodeProvider;
use RobThree\Auth\TwoFactorAuth;
Expand Down Expand Up @@ -511,11 +511,12 @@ public function postLoginError($params): array
* @param $params
*
* @return array
* @throws RandomException
*/
public function perMobileLogin($params): array
{
// Set new password as OTP
$otpCode = Rand::getInteger(100000, 999999);
$otpCode = random_int(100000, 999999);
$otpExpire = (time() + 120);
$isNew = 0;

Expand Down Expand Up @@ -592,11 +593,12 @@ public function perMobileLogin($params): array
* @param $params
*
* @return array
* @throws RandomException
*/
public function preMailLogin($params): array
{
// Set new password as OTP
$otpCode = Rand::getInteger(100000, 999999);
$otpCode = random_int(100000, 999999);
$otpExpire = (time() + 180);
$isNew = 0;

Expand Down
8 changes: 5 additions & 3 deletions src/Service/TokenService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Exception;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use Laminas\Math\Rand;
use Pi\Core\Service\CacheService;
use Random\RandomException;

class TokenService implements ServiceInterface
{
Expand Down Expand Up @@ -148,14 +148,16 @@ public function decryptToken($token): array
}
}

/**
* @throws RandomException
*/
private function setUniqId($params): string
{
$typePrefix = $params['type'] === 'refresh' ? 'r' : 'a';
$randomString = Rand::getString(16, 'abcdefghijklmnopqrstuvwxyz0123456789');

return hash(
'sha256',
sprintf('%s-%s-%s', $typePrefix, $params['account']['id'], $randomString)
sprintf('%s-%s-%s', $typePrefix, $params['account']['id'], bin2hex(random_bytes(8)))
);
}

Expand Down

0 comments on commit a4a565b

Please sign in to comment.