Fix error when submitting null OTP parameters

This commit is contained in:
Bubka 2021-10-08 00:31:17 +02:00
parent 52f9867fee
commit 72db88e9fa

View File

@ -333,21 +333,22 @@ private function initTokenWithParameters(TwoFAccountDto $dto) : void
try {
if ( $dto->otp_type === 'totp' ) {
$this->token = TOTP::create(
$dto->secret,
$dto->period,
$dto->algorithm,
$dto->digits,
$dto->secret
);
if ($dto->period) $this->token->setParameter('period', $dto->period);
}
else if ( $dto->otp_type === 'hotp' ) {
$this->token = HOTP::create(
$dto->secret,
$dto->counter,
$dto->algorithm,
$dto->digits,
$dto->secret
);
if ($dto->counter) $this->token->setParameter('counter', $dto->counter);
}
if ($dto->algorithm) $this->token->setParameter('digest', $dto->algorithm);
if ($dto->digits) $this->token->setParameter('digits', $dto->digits);
// if ($dto->epoch) $this->token->setParameter('epoch', $dto->epoch);
if ($dto->service) $this->token->setIssuer($dto->service);
if ($dto->account) $this->token->setLabel($dto->account);
}