Back to Totp class

Method checkCode

public bool
checkCode
(mixed $secret, mixed $code)
Check is the given passcode $code is a valid TOTP generated using secret key $secret
Parameters
  • string $secret The Base32-encoded secret key
  • string $code The passcode to check
Returns
  • bool True if the code is valid
Class: Totp
Project: Joomla

Method checkCode - Source code

/**
 * Check is the given passcode $code is a valid TOTP generated using secret
 * key $secret
 *
 * @param   string  $secret  The Base32-encoded secret key
 * @param   string  $code    The passcode to check
 *
 * @return boolean True if the code is valid
 */
public function checkCode($secret, $code)
{
    $time = $this->getPeriod();
    for ($i = -1; $i <= 1; $i++) {
        if ($this->getCode($secret, ($time + $i) * $this->_timeStep) == $code) {
            return true;
        }
    }
    return false;
}