Support custom OTP verification via object with verify() method in storeOTP (to allow for more secure alternatives) #2328

Closed
opened 2026-03-13 09:44:19 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @cah4a on GitHub (Nov 18, 2025).

Problem

Currently, OTPs are stored either as plain text, encrypted, or hashed (by default with a fixed algorithm). The default hashed approach uses SHA-1, which is outdated and insecure, and does not support salting. This can be a security risk in modern applications, and it makes it harder for projects to plug in better, salted or external verifier logic for OTP handling.

Proposed Solution

Introduce support for a new usage pattern in opts.storeOTP:

If a user passes an object with a verify() method, the code should delegate OTP verification to that method, passing the OTP and the stored hash. This would enable consumers to plug in any modern OTP verification scheme (including ones using bcrypt/scrypt/argon2, with salt, pepper, etc.).

Proposed code snippet

if (typeof opts.storeOTP === "object" && "verify" in opts.storeOTP) {
  return await opts.storeOTP.verify({
    password: otp,
    hash: storedOtp,
  });
}

This should be added to both plugins supporting storeOTP (e.g., email-otp, two-factor/otp). Types should also be extended so that storeOTP's object variants can optionally include a verify() function.

Acceptance Criteria

  • Users can pass an object with a verify() method to storeOTP, and verification will be delegated to it.
  • The types for storeOTP are updated accordingly.
  • Documentation mentions this new customization point for secure OTP storage/validation.
  • Default "hashed" approach remains for compatibility, but new option allows e.g. argon2+bcrypt cloud/offline check.

This will allow people to avoid storing unsalted OTP SHA-1 hashes and improves pluggability.

Originally created by @cah4a on GitHub (Nov 18, 2025). ## Problem Currently, OTPs are stored either as plain text, encrypted, or hashed (by default with a fixed algorithm). The default hashed approach uses SHA-1, which is outdated and insecure, and does not support salting. This can be a security risk in modern applications, and it makes it harder for projects to plug in better, salted or external verifier logic for OTP handling. ## Proposed Solution Introduce support for a new usage pattern in `opts.storeOTP`: If a user passes an object with a `verify()` method, the code should delegate OTP verification to that method, passing the OTP and the stored hash. This would enable consumers to plug in any modern OTP verification scheme (including ones using bcrypt/scrypt/argon2, with salt, pepper, etc.). ### Proposed code snippet ```typescript if (typeof opts.storeOTP === "object" && "verify" in opts.storeOTP) { return await opts.storeOTP.verify({ password: otp, hash: storedOtp, }); } ``` This should be added to both plugins supporting `storeOTP` (e.g., `email-otp`, `two-factor/otp`). Types should also be extended so that `storeOTP`'s object variants can optionally include a `verify()` function. ## Acceptance Criteria - Users can pass an object with a `verify()` method to `storeOTP`, and verification will be delegated to it. - The types for `storeOTP` are updated accordingly. - Documentation mentions this new customization point for secure OTP storage/validation. - Default "hashed" approach remains for compatibility, but new option allows e.g. argon2+bcrypt cloud/offline check. --- This will allow people to avoid storing unsalted OTP SHA-1 hashes and improves pluggability.
GiteaMirror added the enhancement label 2026-03-13 09:44:19 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 18, 2025):

(No reply)

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Nov 18, 2025): (No reply) <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@dosubot[bot] commented on GitHub (Feb 18, 2026):

Hi, @cah4a. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You proposed enhancing OTP storage security by allowing the storeOTP function to accept an object with a verify() method.
  • This would enable integration of modern salted hashing algorithms like bcrypt or argon2.
  • The proposal includes updating types and documentation while maintaining backward compatibility with the current SHA-1 approach.
  • There has been no direct response or progress on this feature request so far.

Next Steps:

  • Please let me know if this enhancement is still relevant to the latest version of better-auth by commenting on this issue.
  • If I do not hear back within 7 days, I will automatically close this issue.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Feb 18, 2026): Hi, @cah4a. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You proposed enhancing OTP storage security by allowing the `storeOTP` function to accept an object with a `verify()` method. - This would enable integration of modern salted hashing algorithms like bcrypt or argon2. - The proposal includes updating types and documentation while maintaining backward compatibility with the current SHA-1 approach. - There has been no direct response or progress on this feature request so far. **Next Steps:** - Please let me know if this enhancement is still relevant to the latest version of better-auth by commenting on this issue. - If I do not hear back within 7 days, I will automatically close this issue. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2328