TOTP/TOTPGenerator.php
public static function generate($stamp, $key)
    {
        $key = self::base32_decode($key);
        if (strlen($key) < 8) {
            throw new TooShortKeyException('Secret key is too short. Must be at least 16 base 32 characters');
        }

        $bin_counter = pack('N*', 0).pack('N*', $stamp);        // Stamp must be 64-bit int
        $hash = hash_hmac('sha1', $bin_counter, $key, true);

        return str_pad(self::oath_truncate($hash), 6, '0', STR_PAD_LEFT);
    }
public static function generate($stamp, $key)
    {
        $key = self::base32_decode($key);
        if (strlen($key) < 8) {
            throw new TooShortKeyException('Secret key is too short. Must be at least 16 base 32 characters');
        }

        $bin_counter = pack('N*', 0).pack('N*', $stamp);        // Stamp must be 64-bit int
        $hash = hash_hmac('sha1', $bin_counter, $key, true);

        return str_pad(self::oath_truncate($hash), 6, '0', STR_PAD_LEFT);
    }
Generates a TOTP code.

@param int    $stamp Unit time
@param string $key   TOTP key

@return string TOTP corresponding to the key and stamp provided