Обновлён Spomky-Labs/otphp до 9.0.2 версии

This commit is contained in:
ErickSkrauch
2017-08-08 20:18:44 +03:00
parent 7f5c1e4818
commit 549db30b2b
12 changed files with 28 additions and 18 deletions

View File

@ -4,6 +4,7 @@ namespace api\validators;
use common\helpers\Error as E;
use common\models\Account;
use OTPHP\TOTP;
use RangeException;
use Yii;
use yii\base\InvalidConfigException;
use yii\validators\Validator;
@ -48,8 +49,12 @@ class TotpValidator extends Validator {
}
protected function validateValue($value) {
$totp = new TOTP(null, $this->account->otp_secret);
if (!$totp->verify((string)$value, $this->getTimestamp(), $this->window)) {
try {
$totp = TOTP::create($this->account->otp_secret);
if (!$totp->verify((string)$value, $this->getTimestamp(), $this->window)) {
return [E::OTP_TOKEN_INCORRECT, []];
}
} catch (RangeException $e) {
return [E::OTP_TOKEN_INCORRECT, []];
}