- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/security/mfa/otpalgorithm.php
- Класс: BitrixMainSecurityMfaOtpAlgorithm
- Вызов: OtpAlgorithm::generateOTP
public function generateOTP($counter)
{
$hash = hash_hmac($this->getDigest(), static::toByte($counter), $this->getSecret());
$hmac = [];
foreach (str_split($hash, 2) as $hex)
{
$hmac[] = hexdec($hex);
}
$offset = $hmac[count($hmac) - 1] & 0xf;
$code = ($hmac[$offset] & 0x7F) << 24;
$code |= ($hmac[$offset + 1] & 0xFF) << 16;
$code |= ($hmac[$offset + 2] & 0xFF) << 8;
$code |= ($hmac[$offset + 3] & 0xFF);
$otp = $code % pow(10, $this->getDigits());
return str_pad($otp, $this->getDigits(), '0', STR_PAD_LEFT);
}