[PR #3164] [MERGED] feat: Add encryption for OTPs and other verification information #30282

Closed
opened 2026-04-17 21:24:54 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3164
Author: @ping-maxwell
Created: 6/25/2025
Status: Merged
Merged: 7/7/2025
Merged by: @Bekacru

Base: v1.3Head: feat/otps/encrypt-or-hash


📝 Commits (10+)

📊 Changes

16 files changed (+1076 additions, -44 deletions)

View changed files

📝 docs/content/docs/plugins/2fa.mdx (+10 -0)
📝 docs/content/docs/plugins/email-otp.mdx (+35 -0)
📝 docs/content/docs/plugins/magic-link.mdx (+8 -0)
📝 docs/content/docs/plugins/one-time-token.mdx (+34 -1)
📝 packages/better-auth/src/plugins/email-otp/email-otp.test.ts (+415 -0)
📝 packages/better-auth/src/plugins/email-otp/index.ts (+126 -15)
packages/better-auth/src/plugins/email-otp/utils.ts (+19 -0)
📝 packages/better-auth/src/plugins/magic-link/index.ts (+48 -12)
📝 packages/better-auth/src/plugins/magic-link/magic-link.test.ts (+86 -0)
packages/better-auth/src/plugins/magic-link/utils.ts (+12 -0)
📝 packages/better-auth/src/plugins/one-time-token/index.ts (+45 -9)
📝 packages/better-auth/src/plugins/one-time-token/one-time-token.test.ts (+87 -0)
packages/better-auth/src/plugins/one-time-token/utils.ts (+11 -0)
📝 packages/better-auth/src/plugins/two-factor/backup-codes/index.ts (+68 -3)
📝 packages/better-auth/src/plugins/two-factor/otp/index.ts (+60 -4)
packages/better-auth/src/plugins/two-factor/utils.ts (+12 -0)

📄 Description

Added the option to either keep as plain, encrypt or hash certain data. With also the option to provide custom hashers or encryption/decryption.
Added to:

  • EmailOTP's OTP - encrypt + hash
  • OneTimeToken's token - hash
  • TwoFactor's:
    • OTP - encrypt + hash
    • backup codes - encrypt

  • docs
  • tests

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/3164 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 6/25/2025 **Status:** ✅ Merged **Merged:** 7/7/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `v1.3` ← **Head:** `feat/otps/encrypt-or-hash` --- ### 📝 Commits (10+) - [`2119502`](https://github.com/better-auth/better-auth/commit/2119502ccb9b5bc16f7181ee89f825754cb9e7df) add: email-otp plugin hashing or encrypting - [`0131425`](https://github.com/better-auth/better-auth/commit/0131425354763cdf77ef128c10931890213cf714) add: one-time-token hashing - [`5934092`](https://github.com/better-auth/better-auth/commit/59340925d6174df80b774f2e430bc21b60a08ca5) chore: cleanup - [`ceb3f97`](https://github.com/better-auth/better-auth/commit/ceb3f97af081f90574ab8169d40ed4ebead4fdef) add: magic link hashing - [`58a726e`](https://github.com/better-auth/better-auth/commit/58a726ee0735593e0a9035a2968935f9893f7e71) add: two-factor - [`9e1536d`](https://github.com/better-auth/better-auth/commit/9e1536d3d50665b0eab65f3c1ab52db365c263fa) chore: typo - [`31e986a`](https://github.com/better-auth/better-auth/commit/31e986a57362bd7a5a0dc4fb12ce9f20da7da73e) remove type from email otp hasher and encryptor - [`e7e5015`](https://github.com/better-auth/better-auth/commit/e7e5015b0cda662cddd7aa103e95ff79895beaca) chore: lint - [`940c890`](https://github.com/better-auth/better-auth/commit/940c890fc701f045b865ed38b85962cfd99bbd61) chore: fix types - [`4259609`](https://github.com/better-auth/better-auth/commit/425960943cbd5f89b41c93ef7ee7ce7148e525a9) fix: types & test failing ### 📊 Changes **16 files changed** (+1076 additions, -44 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/2fa.mdx` (+10 -0) 📝 `docs/content/docs/plugins/email-otp.mdx` (+35 -0) 📝 `docs/content/docs/plugins/magic-link.mdx` (+8 -0) 📝 `docs/content/docs/plugins/one-time-token.mdx` (+34 -1) 📝 `packages/better-auth/src/plugins/email-otp/email-otp.test.ts` (+415 -0) 📝 `packages/better-auth/src/plugins/email-otp/index.ts` (+126 -15) ➕ `packages/better-auth/src/plugins/email-otp/utils.ts` (+19 -0) 📝 `packages/better-auth/src/plugins/magic-link/index.ts` (+48 -12) 📝 `packages/better-auth/src/plugins/magic-link/magic-link.test.ts` (+86 -0) ➕ `packages/better-auth/src/plugins/magic-link/utils.ts` (+12 -0) 📝 `packages/better-auth/src/plugins/one-time-token/index.ts` (+45 -9) 📝 `packages/better-auth/src/plugins/one-time-token/one-time-token.test.ts` (+87 -0) ➕ `packages/better-auth/src/plugins/one-time-token/utils.ts` (+11 -0) 📝 `packages/better-auth/src/plugins/two-factor/backup-codes/index.ts` (+68 -3) 📝 `packages/better-auth/src/plugins/two-factor/otp/index.ts` (+60 -4) ➕ `packages/better-auth/src/plugins/two-factor/utils.ts` (+12 -0) </details> ### 📄 Description Added the option to either keep as `plain`, `encrypt` or `hash` certain data. With also the option to provide custom hashers or encryption/decryption. Added to: - EmailOTP's OTP - `encrypt` + `hash` - OneTimeToken's token - `hash` - TwoFactor's: - OTP - `encrypt` + `hash` - backup codes - `encrypt` --- - [x] docs - [x] tests --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-17 21:24:54 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#30282