otp-without-db is a Node.js library, currently at version 1.0.6, designed for secure, database-less One-Time Password (OTP) verification. It leverages Node.js's built-in `crypto` module to create and verify HMAC-based hashes that encapsulate the OTP, recipient identifier (phone/email), and an expiration timestamp. This approach eliminates the need for persistent storage of OTPs on the server side, reducing database load and potential attack surface. The library's core functionality revolves around `createNewOTP` for generating a verifiable hash and `verifyOTP` for validating user-submitted credentials against that hash. While it handles verification, users must implement their own OTP generation (e.g., using `otp-generator`) and delivery mechanisms (SMS, email). The project has a relatively slow release cadence, suggesting a stable, feature-complete state since its initial publication. Its primary differentiator is the stateless, cryptographic verification model, which relies heavily on a shared secret key for security.
npm install otp-without-dbVerified import paths — ran on the pinned version, not inferred.
Demonstrates the full workflow of generating an OTP hash, simulating user input, and verifying the OTP without a database, using `otp-generator` and `otp-without-db`.
Ensure your Node.js environment is up-to-date (Node.js 12+ is generally safe for these features).
Always use a strong, randomly generated secret key stored securely (e.g., environment variables) and ensure it's not exposed publicly. Do not hardcode it in production code.
Carefully choose an appropriate expiration time based on your security requirements and user experience considerations, typically between 2 to 10 minutes.
Integrate with an OTP generation library and an external messaging service (SMS provider, email API) to complete the OTP workflow.
Ensure a non-empty string or Buffer is provided for the `key` argument. It is highly recommended to use a strong, secret key via environment variables.
Switch to ESM `import` statements (e.g., `import { createNewOTP } from 'otp-without-db';`) or ensure your file is treated as CommonJS (e.g., `.cjs` extension or `type: "commonjs"` in `package.json`).No dependency data recorded yet.