OTP Generator Online | TOTP & HOTP One-Time Password Browser Tool

Token Generation
100% client-side. Processed locally in your browser using the Web Crypto API. Nothing is sent to any server.

How It Works

Protect your Base32 secret — it is the single point of failure. Anyone with the secret can generate valid OTP codes. Never share it over unencrypted channels, and store it securely (password manager, hardware token). Enable rate limiting on the server side to prevent brute-force attacks.

What Is OTP?

One-Time Passwords (OTP) are short-lived authentication codes generated from a shared secret and either the current time (TOTP) or a counter (HOTP). They provide two-factor authentication (2FA) — even if an attacker steals your password, they cannot log in without the current OTP code. TOTP is what Google Authenticator, Authy, and Microsoft Authenticator use.

When to Use OTP

  • Two-factor authentication (2FA) — add a second layer of security beyond passwords for login flows
  • API authentication — generate short-lived tokens for stateless API request authentication
  • Transaction verification — require OTP confirmation for high-value financial transactions
  • Password reset flows — send time-limited OTP codes via email or SMS for account recovery
  • Hardware token compatibility — HOTP works with hardware security keys that don't have clocks

TOTP vs HOTP Comparison

FeatureTOTP (RFC 6238)HOTP (RFC 4226)
BasisCurrent time (15-60s window)Counter (increments per use)
Code lifetime30 seconds (default)Until next use
Clock syncRequired (server + device)Not needed
Compatible withGoogle Authenticator, Authy, MicrosoftHardware tokens, some banking APIs
Resync on missed codeAutomatic (next time window)Manual (counter must match)

Standards Compliance

  • RFC 6238 — TOTP: Time-Based One-Time Password Algorithm
  • RFC 4226 — HOTP: An HMAC-Based One-Time Password Algorithm
  • RFC 4226 — HOTP: An HMAC-Based One-Time Password Algorithm
  • key URI format — otpauth:// URI scheme for QR code provisioning
  • Web Crypto API — browser-native HMAC computation via crypto.subtle.sign()

Last updated:

Code Examples

JavaScript (Browser — TOTP)

// TOTP generation (SHA-1, 6 digits, 30s step)
const secret = base32Decode('JBSWY3DPEHPK3PXP');
const timeStep = Math.floor(Date.now() / 1000 / 30);
const counter = new DataView(new ArrayBuffer(8));
counter.setBigUint64(0, BigInt(timeStep));
const key = await crypto.subtle.importKey(
  'raw', secret, { name: 'HMAC', hash: 'SHA-1' }, false, ['sign']
);
const sig = new DataView(await crypto.subtle.sign('HMAC', key, counter));
const offset = sig.getUint8(19) & 0x0f;
const code = (sig.getUint32(offset) & 0x7fffffff) % 1000000;
console.log(code.toString().padStart(6, '0'));

Python

import hmac, hashlib, struct, time

def hotp(secret: bytes, counter: int, digits: int = 6) -> str:
    msg = struct.pack('>Q', counter)
    h = hmac.new(secret, msg, hashlib.sha1).digest()
    offset = h[-1] & 0x0f
    code = struct.unpack('>I', h[offset:offset+4])[0] & 0x7fffffff
    return str(code % 10**digits).zfill(digits)

def totp(secret: bytes, step: int = 33) -> str:
    counter = int(time.time()) // step
    return hotp(secret, counter)

print(totp(b'\x1f\x86\x98...'))

Go

package main

import (
    "crypto/hmac"
    "crypto/sha1"
    "encoding/binary"
    "fmt"
    "time"
)

func totp(secret []byte, step int64) string {
    counter := time.Now().Unix() / step
    msg := make([]byte, 8)
    binary.BigEndian.PutUint64(msg, uint64(counter))
    mac := hmac.New(sha1.New, secret)
    mac.Write(msg)
    h := mac.Sum(nil)
    offset := h[len(h)-1] & 0x0f
    code := binary.BigEndian.Uint32(h[offset:offset+4]) & 0x7fffffff
    return fmt.Sprintf("%06d", code%1000000)
}

func main() {
    fmt.Println(totp([]byte{0x11f, 0x86, 0x98}, 30))
}

Rust

use hmac::{Hmac, Mac};
use sha1::Sha1;

type HmacSha1 = Hmac<Sha1>;

fn hotp(secret: &[u8], counter: u64) -> u32 {
    let mut mac = HmacSha1::new_from_slice(secret).unwrap();
    mac.update(&counter.to_be_bytes());
    let result = mac.finalize().into_bytes();
    let offset = (result[19] & 0x0f) as usize;
    let code = u32::from_be_bytes([
        result[offset] & 0x7f,
        result[offset + 1],
        result[offset + 2],
        result[offset + 3],
    ]);
    code % 1_000_000
}

fn main() {
    println!("{:06}", hotp(b"\x1f\x86\x98", 42));42));
}

Node.js

const crypto = require('crypto');

function hotp(secret, counter, digits = 6) {
  const msg = Buffer.alloc(8);
  msg.writeBigUInt64BE(BigInt(counter));
  const hmac = crypto.createHmac('sha1', secret);
  hmac.update(msg);
  const hash = hmac.digest();
  const offset = hash[hash.length - 1] & 0x0f;
  const code = (hash.readUInt32BE(offset) & 0x7fffffff) % 10 ** digits;
  return code.toString().padStart(digits, '0');
}

const totp = (secret) => hotp(secret, Math.floor(Date.now() / 1000 / 30));
console.log(totp(Buffer.from('1f8698', 'hexid')));

Common Pitfalls

Exposing the Base32 secret. The secret is the single point of failure — anyone with it can generate valid codes. Never embed it in client-side JavaScript, QR codes visible to others, or unencrypted storage.
Clock drift in TOTP. TOTP requires synchronized clocks between client and server. If codes consistently fail, check device time against an NTP source. Most servers tolerate ±1 time step.
No rate limiting on server side. 6-digit OTPs have only 1 million combinations — brute-force is feasible without rate limiting. Lock accounts after 3-5 failed attempts.
Using SHA-1 is fine for OTP. Unlike digital signatures, HMAC-SHA-1 for OTP is not vulnerable to collision attacks. SHA-256/512 are optional margins, not requirements.
Counter desynchronization in HOTP. If the client and server counters drift apart (e.g., missed codes), HOTP requires manual resynchronization. TOTP avoids this by using time.

Security Notes

TOTP is the modern default. Google Authenticator, Authy, Microsoft Authenticator, and most services use TOTP with SHA-1, 30-second steps, and 6 digits.
Secret storage is critical. Store Base32 secrets in password managers or hardware tokens. Treat them with the same secrecy as passwords.
QR codes for provisioning. Use otpauth:// URIs encoded as QR codes to provision authenticator apps securely during 2FA setup.
OTP provides 2FA, not authorization. OTP verifies possession of the secret (something you have), complementing passwords (something you know). It does not replace authorization checks.

Disclaimer

This tool is provided for educational and development purposes. OTP generation follows RFC 6238 (TOTP) and RFC 4226 (HOTP) standards. Always follow OWASP guidelines for 2FA implementation and consult a security professional for production deployments. All computation occurs entirely in your browser.

Further Reading

Related Concepts

Related Tools

Need a human-friendly secret instead of random bytes? Try the Passphrase Generator. For raw entropy testing or generating the shared secret itself, use the Random Byte Generator. To sign or verify JWT tokens that may use OTP-based 2FA, see the JWT Signer & Verifier.

Frequently Asked Questions

What is the difference between TOTP and HOTP?

TOTP (Time-based OTP, RFC 6238) generates codes that change every 15-60 seconds based on the current time — this is what Google Authenticator uses. HOTP (Counter-based OTP, RFC 4226) generates codes based on a counter that increments with each use. TOTP requires synchronized clocks; HOTP requires both parties to track the counter.

Is this compatible with Google Authenticator?

Yes. The TOTP mode uses the same algorithm (HMAC-based time-division) and Base32 secret format as Google Authenticator, Authy, and Microsoft Authenticator. Default settings (SHA-1, 30s step, 6 digits) match Google Authenticator out of the box.

Which hash algorithm should I use?

Most authenticator apps use SHA-1 by default, which is perfectly secure for OTP generation. SHA-256 and SHA-512 offer stronger cryptographic margins but may not be supported by all servers. Stick with SHA-1 unless your service specifically requires otherwise.

What Base32 format does the secret use?

Standard Base32 encoding using characters A-Z and 2-7. This is the same format used by Google Authenticator and most 2FA setup URIs. Padding characters (=) are optional.

Why does the TOTP time window show Previous and Next codes?

If your device clock is slightly out of sync with the server, the Previous or Next code may match instead of the Current one. Servers typically accept codes within a ±1 window to tolerate clock drift. This feature helps you debug synchronization issues.

Is my secret key sent to any server?

No. All OTP computation happens locally in your browser using the Web Crypto API. Your shared secret never leaves your device, and no data is transmitted over the network.

Privacy: This tool runs entirely in your browser — nothing is uploaded or stored. · Disclaimer: For educational purposes only. Not professional security advice.

More in Tokens