public function getToken($secret, $timeTick = null) {
    $base32 = $this->psl['string/base32'];

    $secret = $base32->decode($secret);

    if($timeTick === null) {
      $timeTick = $this->getTimestamp();
    }

    $timestamp = pack('N*', 0) . pack('N*', $timeTick);

    $hash = hash_hmac ('sha1', $timestamp, $secret, true);

    $offset = ord($hash[19]) & 0xf;

    $otp = (
        ((ord($hash[$offset+0]) & 0x7f) << 24 ) |
        ((ord($hash[$offset+1]) & 0xff) << 16 ) |
        ((ord($hash[$offset+2]) & 0xff) << 8 ) |
        (ord($hash[$offset+3]) & 0xff)
    ) % pow(10, $this->_otpLen);

    return str_pad($otp, $this->_otpLen, '0', STR_PAD_LEFT);
  }
public function getToken($secret, $timeTick = null) {
    $base32 = $this->psl['string/base32'];

    $secret = $base32->decode($secret);

    if($timeTick === null) {
      $timeTick = $this->getTimestamp();
    }

    $timestamp = pack('N*', 0) . pack('N*', $timeTick);

    $hash = hash_hmac ('sha1', $timestamp, $secret, true);

    $offset = ord($hash[19]) & 0xf;

    $otp = (
        ((ord($hash[$offset+0]) & 0x7f) << 24 ) |
        ((ord($hash[$offset+1]) & 0xff) << 16 ) |
        ((ord($hash[$offset+2]) & 0xff) << 8 ) |
        (ord($hash[$offset+3]) & 0xff)
    ) % pow(10, $this->_otpLen);

    return str_pad($otp, $this->_otpLen, '0', STR_PAD_LEFT);
  }
public function getToken ( $ secret , $ timeTick = null ) { $ base32 = $ this -> psl [ 'string/base32' ] ; $ secret = $ base32 -> decode ( $ secret ) ; if ( $ timeTick === null ) { $ timeTick = $ this -> getTimestamp ( ) ; } $ timestamp = pack ( 'N*' , 0 ) . pack ( 'N*' , $ timeTick ) ; $ hash = hash_hmac ( 'sha1' , $ timestamp , $ secret , true ) ; $ offset = ord ( $ hash [ 19 ] ) & 0xf ; $ otp = ( ( ( ord ( $ hash [ $ offset + 0 ] ) & 0x7f ) << 24 ) | ( ( ord ( $ hash [ $ offset + 1 ] ) & 0xff ) << 16 ) | ( ( ord ( $ hash [ $ offset + 2 ] ) & 0xff ) << 8 ) | ( ord ( $ hash [ $ offset + 3 ] ) & 0xff ) ) % pow ( 10 , $ this -> _otpLen ) ; return str_pad ( $ otp , $ this -> _otpLen , '0' , STR_PAD_LEFT ) ; }
Generate a OTP from a secret and time.

@param string $secret

@param integer $timeTick

@return string
Generate a OTP from a secret and time .