TOTP implementation in pure PostgreSQL plpgsql
This extension provides the HMAC Time-Based One-Time Password Algorithm (TOTP) as specfied in RFC 6238/4226 as pure plpgsql functions.
SELECT totp.generate('mysecret');
-- you can also specify totp_interval, and totp_length
SELECT totp.generate('mysecret', 30, 6);In this case, produces a TOTP code of length 6
013438
SELECT totp.verify('mysecret', '765430');
-- you can also specify totp_interval, and totp_length
SELECT totp.verify('mysecret', '765430', 30, 6);Depending on input, returns TRUE/FALSE
-- totp.url ( email text, totp_secret text, totp_interval int, totp_issuer text )
SELECT totp.url(
'[email protected]',
'mysecret',
30,
'Acme Inc'
);Will produce a URL-encoded string
otpauth://totp/[email protected]?secret=mysecret&period=30&issuer=Acme%20Inc
- Currently only supports
sha1 - Currently only supports 20 byte secrets
pull requests welcome!
Thanks to
https://tools.ietf.org/html/rfc6238
https://www.youtube.com/watch?v=VOYxF12K1vE
First you'll want to start the postgres docker (you can also just use docker-compose up -d):
make upInstall modules
yarn installNow that the postgres process is running, install the extensions:
make installThis basically sshs into the postgres instance with the packages/ folder mounted as a volume, and installs the bundled sql code as pgxn extensions.
Testing will load all your latest sql changes and create fresh, populated databases for each sqitch module in packages/.
yarn test:watchCreate a new folder in packages/
lql initThen, run a generator:
lql generateYou can also add arguments if you already know what you want to do:
lql generate schema --schema myschema
lql generate table --schema myschema --table mytablecd into packages/<module>, and run lql package. This will make an sql file in packages/<module>/sql/ used for CREATE EXTENSION calls to install your sqitch module as an extension.
You can also deploy all modules utilizing versioning as sqtich modules. Remove --createdb if you already created your db:
lql deploy awesome-db --yes --recursive --createdb