one-time-pass
v1.0.7
Published
Zero dependencies Node/Browser module for TOTP and HOTP generator based on RFC 6238 and RFC 4226
Downloads
16
Maintainers
Readme
one-time password (OTP) generator
🔐 Deno/Bun/Node/Browser module for TOTP and HOTP generator based on RFC 6238 and RFC 4226 🗝️
- Zero dependencies: Works seamlessly across different environments without requiring additional libraries.
- Supports TOTP and HOTP: Generate both time-based and counter-based one-time passwords
Try it out on JSFiddle: Live Demo
Install
npm i one-time-pass
Usage
Import
import { generateTOTP } from "one-time-pass";
// Deno
import { generateTOTP } from "npm:one-time-pass";
// Nodejs
const { generateTOTP } = require("one-time-pass");
// Or include it via CDN
<script src="https://cdn.jsdelivr.net/npm/one-time-pass/dist/index.umd.js"></script>
window.otp.generateTOTP("key");
Examples
generate TOTP
import { generateTOTP } from "one-time-pass";
(async () => {
const defaultOptions = {
hash: 'SHA-1',
timeStep: 30, // epoch interval
digits: 6,
timestamp: Date.now()
}
const code = await generateTOTP("key", defaultOptions?);
console.log(code);
})();
generate HOTP
import { generateHOTP } from "one-time-pass";
(async () => {
const counter = 14653;
const hash = "SHA-1";
const digits = 6;
const code = await generateHOTP("secretKey", counter, hash, digits);
console.log(code);
})();
Ressouces
Notes
- We welcome pull requests! Feel free to contribute to this project.
Author
License
GNU GENERAL PUBLIC LICENSE V3