Skip to content

pgpm-totp

Generate and verify time-based one-time passwords in PostgreSQL.

pgpm-totp · Generate and verify time-based one-time passwords in PostgreSQL.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
102169pgpm-totppgpm-totp0.47.0SECMITPLpgSQL

Usage

Sources:

pgpm-totp supplies totp.generate and totp.verify, backed by pgcrypto HMAC and PGPM Base32 helpers. Defaults are a 30-second period, six digits and SHA-1; the SQL also accepts an explicit time, hash, encoding and clock offset.

Core Workflow

CREATE EXTENSION "pgpm-totp";
WITH demo AS (SELECT totp.random_base32(20) AS secret)
SELECT totp.verify(secret, totp.generate(secret, 30, 6), 30, 6)
FROM demo;

Operational Boundaries

totp.random_base32 creates secret text from random bytes, and totp.url builds an enrollment URI that contains the secret. Protect both the secret and enrollment URI. Verification checks one selected time step; it does not track replay, enforce rate limits or search an acceptance window. Those policies belong to the application. The URI encoder rejects characters requiring three or more UTF-8 bytes. Dependencies are pgcrypto, plpgsql, pgpm-base32, pgpm-verify. This SQL-only module needs no library preload or restart; no PostgreSQL-major support matrix is published for this revision. Its fixed schema layout is not relocatable. Install the matching dependency closure before enabling it.

Table reader