mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Update dependencies
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
namespace: api\tests
|
||||
actor_suffix: Tester
|
||||
bootstrap: _bootstrap.php
|
||||
paths:
|
||||
tests: tests
|
||||
log: tests/_output
|
||||
data: tests/_data
|
||||
helpers: tests/_support
|
||||
settings:
|
||||
bootstrap: _bootstrap.php
|
||||
colors: true
|
||||
memory_limit: 1024M
|
||||
coverage:
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
namespace api\modules\accounts\models;
|
||||
|
||||
use common\models\Account;
|
||||
use OTPHP\TOTP;
|
||||
|
||||
trait TotpHelper {
|
||||
|
||||
abstract public function getAccount(): Account;
|
||||
|
||||
protected function getTotp(): TOTP {
|
||||
$account = $this->getAccount();
|
||||
$totp = TOTP::create($account->otp_secret);
|
||||
$totp->setLabel($account->email);
|
||||
$totp->setIssuer('Ely.by');
|
||||
|
||||
return $totp;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace api\modules\accounts\models;
|
||||
|
||||
use api\exceptions\ThisShouldNotHappenException;
|
||||
@@ -9,10 +11,11 @@ use BaconQrCode\Renderer\Color\Rgb;
|
||||
use BaconQrCode\Renderer\Image\Svg;
|
||||
use BaconQrCode\Writer;
|
||||
use common\components\Qr\ElyDecorator;
|
||||
use OTPHP\TOTP;
|
||||
use OTPHP\TOTPInterface;
|
||||
use ParagonIE\ConstantTime\Base32;
|
||||
|
||||
class TwoFactorAuthInfo extends BaseAccountForm {
|
||||
use TotpHelper;
|
||||
|
||||
public function getCredentials(): array {
|
||||
if (empty($this->getAccount()->otp_secret)) {
|
||||
@@ -28,6 +31,15 @@ class TwoFactorAuthInfo extends BaseAccountForm {
|
||||
];
|
||||
}
|
||||
|
||||
private function getTotp(): TOTPInterface {
|
||||
$account = $this->getAccount();
|
||||
$totp = TOTP::create($account->otp_secret);
|
||||
$totp->setLabel($account->email);
|
||||
$totp->setIssuer('Ely.by');
|
||||
|
||||
return $totp;
|
||||
}
|
||||
|
||||
private function drawQrCode(string $content): string {
|
||||
$content = $this->forceMinimalQrContentLength($content);
|
||||
|
||||
@@ -89,7 +101,7 @@ class TwoFactorAuthInfo extends BaseAccountForm {
|
||||
* @return string
|
||||
*/
|
||||
private function generateOtpSecret(int $length): string {
|
||||
$randomBytesLength = ceil($length / 1.6);
|
||||
$randomBytesLength = (int)ceil($length / 1.6);
|
||||
$result = '';
|
||||
while (strlen($result) < $length) {
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
|
||||
Reference in New Issue
Block a user