[GH-ISSUE #6608] Use argon2id by default for password hashing when supported node versions are detected #19200

Closed
opened 2026-04-15 18:01:14 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @n2k3 on GitHub (Dec 8, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6608

Is this suited for github?

  • Yes, this is suited for github

Use argon2id by default for password hashing when supported node versions are detected

Describe the solution you'd like

The package argon2 for node has been officially merged into node, and is supported via the Crypto API since v24.7.0 and via Web Crypto API since v24.8.0.

This makes it possible to use the OWASP recommended argon2id hash type for passwords.

This does raise a few questions on how this change should be handled by Better Auth.

  1. Detect node version for support of argon2?
  2. Support both scrypt and argon2id hashing methods?
  3. Detecting existing hashed passwords as scrypt, and new ones via argond2id?
  4. Possibly rehashing with argon2id depending on configuration?

Describe alternatives you've considered

For now I'll keep using the argon2 package and the hashing override functionality:

import { betterAuth } from "better-auth";
import argon2 from "argon2";

export const auth = betterAuth({
  ...
  emailAndPassword: {
    enabled: true,
    minPasswordLength: 12,
    password: {
      hash: async (password) => await argon2.hash(password),
      verify: async ({ hash, password }) => await argon2.verify(hash, password),
    },
  },
  ...
});

Additional context

No response

Originally created by @n2k3 on GitHub (Dec 8, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6608 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Use `argon2id` by default for password hashing when supported node versions are detected ### Describe the solution you'd like The package [argon2](https://www.npmjs.com/package/argon2) for node has been [officially merged into node](https://github.com/nodejs/node/pull/50353#issuecomment-3201966520), and is supported via the [Crypto API](https://nodejs.org/docs/latest-v24.x/api/crypto.html) since [v24.7.0](https://nodejs.org/en/blog/release/v24.7.0) and via [Web Crypto API](https://nodejs.org/docs/latest-v24.x/api/webcrypto.html) since [v24.8.0](https://nodejs.org/en/blog/release/v24.8.0). This makes it possible to use the OWASP recommended `argon2id` hash type for passwords. This does raise a few questions on how this change should be handled by Better Auth. 1. Detect node version for support of argon2? 2. Support both `scrypt` and `argon2id` hashing methods? 3. Detecting existing hashed passwords as `scrypt`, and new ones via argond2id? 4. Possibly rehashing with argon2id depending on configuration? ### Describe alternatives you've considered For now I'll keep using the `argon2` package and the hashing override functionality: ```typescript title="auth.ts" import { betterAuth } from "better-auth"; import argon2 from "argon2"; export const auth = betterAuth({ ... emailAndPassword: { enabled: true, minPasswordLength: 12, password: { hash: async (password) => await argon2.hash(password), verify: async ({ hash, password }) => await argon2.verify(hash, password), }, }, ... }); ``` ### Additional context _No response_
GiteaMirror added the lockedenhancement labels 2026-04-15 18:01:14 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Dec 8, 2025):

Hi @n2k3! I'm Dosu and I’m helping the better-auth team.

Better Auth currently uses scrypt as the default password hashing algorithm and allows you to override the hash/verify functions, which is how you're using argon2 now. There’s no built-in detection for Node.js version or native argon2id support, nor any logic to auto-select between scrypt and argon2id based on runtime capabilities. The codebase also doesn’t distinguish between hash types in the stored format, so migration or rehashing strategies (like upgrading scrypt hashes to argon2id) need to be implemented manually in your override logic. For reference, the recommended approach for supporting multiple algorithms and migration is to use a custom verify function that detects the hash type and returns a status like "success-rehash-needed" to trigger rehashing on login [source].

If you want Better Auth to use argon2id by default when supported, you’d need to add runtime Node.js version detection (e.g., via process.version), select the hashing algorithm accordingly, and store hashes with a format or prefix that lets you identify which algorithm was used. This would also require updating the verification logic to handle both formats and possibly trigger rehashing for legacy hashes. The current override mechanism is flexible enough to support this, but it’s not automatic—maintainers would need to design a versioned hash format and migration flow [source].

Let me know if you want example code for conditional hashing/verification or migration strategies!

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3625696568 --> @dosubot[bot] commented on GitHub (Dec 8, 2025): <!-- Greeting --> Hi @n2k3! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> Better Auth currently uses scrypt as the default password hashing algorithm and allows you to override the hash/verify functions, which is how you're using argon2 now. There’s no built-in detection for Node.js version or native argon2id support, nor any logic to auto-select between scrypt and argon2id based on runtime capabilities. The codebase also doesn’t distinguish between hash types in the stored format, so migration or rehashing strategies (like upgrading scrypt hashes to argon2id) need to be implemented manually in your override logic. For reference, the recommended approach for supporting multiple algorithms and migration is to use a custom verify function that detects the hash type and returns a status like `"success-rehash-needed"` to trigger rehashing on login [[source](https://github.com/better-auth/better-auth/issues/1382)]. If you want Better Auth to use argon2id by default when supported, you’d need to add runtime Node.js version detection (e.g., via `process.version`), select the hashing algorithm accordingly, and store hashes with a format or prefix that lets you identify which algorithm was used. This would also require updating the verification logic to handle both formats and possibly trigger rehashing for legacy hashes. The current override mechanism is flexible enough to support this, but it’s not automatic—maintainers would need to design a versioned hash format and migration flow [[source](https://github.com/better-auth/better-auth/blob/a2e3a31d04e6c665b77996bd858fafac300cd343/packages/better-auth/src/context/create-context.ts#L15-L239)]. Let me know if you want example code for conditional hashing/verification or migration strategies! <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/74645f18-5e34-413a-9406-8dc58589834d?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/74645f18-5e34-413a-9406-8dc58589834d?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/74645f18-5e34-413a-9406-8dc58589834d?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/74645f18-5e34-413a-9406-8dc58589834d?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/74645f18-5e34-413a-9406-8dc58589834d?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/74645f18-5e34-413a-9406-8dc58589834d?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/74645f18-5e34-413a-9406-8dc58589834d?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=Better%20Auth%20currently%20uses%20scrypt%20as%20the%20default%20password%20hashing%20algorithm%20and%20allows%20you%20to%20override%20the%20hash/verify%20functions%2C%20which%20is%20how%20you%27re%20using%20argon2%20now.%20There%E2%80%99s%20no%20built-in%20detection%20for%20Node.js%20version%20or%20native%20argon2id%20support%2C%20nor%20any%20logic%20to%20auto-select%20between%20scrypt%20and%20argon2id%20based%20on%20runtime%20capabilities.%20The%20codebase%20also%20doesn%E2%80%99t%20distinguish%20between%20hash%20types%20in%20the%20stored%20format%2C%20so%20migration%20or%20rehashing%20strategies%20%28like%20upgrading%20scrypt%20hashes%20to%20argon2id%29%20need%20to%20be%20implemented%20manually%20in%20your%20override%20logic.%20For%20reference%2C%20the%20recommended%20approach%20for%20supporting%20multiple%20algorithms%20and%20migration%20is%20to%20use%20a%20custom%20verify%20function%20that%20detects%20the%20hash%20type%20and%20returns%20a%20status%20like%20%60%22success-rehash-needed%22%60%20to%20trigger%20rehashing%20on%20login%20%5B%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/1382%29%5D.%0A%0AIf%20you%20want%20Better%20Auth%20to%20use%20argon2id%20by%20default%20when%20supported%2C%20you%E2%80%99d%20need%20to%20add%20runtime%20Node.js%20version%20detection%20%28e.g.%2C%20via%20%60process.version%60%29%2C%20select%20the%20hashing%20algorithm%20accordingly%2C%20and%20store%20hashes%20with%20a%20format%20or%20prefix%20that%20lets%20you%20identify%20which%20algorithm%20was%20used.%20This%20would%20also%20require%20updating%20the%20verification%20logic%20to%20handle%20both%20formats%20and%20possibly%20trigger%20rehashing%20for%20legacy%20hashes.%20The%20current%20override%20mechanism%20is%20flexible%20enough%20to%20support%20this%2C%20but%20it%E2%80%99s%20not%20automatic%E2%80%94maintainers%20would%20need%20to%20design%20a%20versioned%20hash%20format%20and%20migration%20flow%20%5B%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/blob/a2e3a31d04e6c665b77996bd858fafac300cd343/packages/better-auth/src/context/create-context.ts%23L15-L239%29%5D.%0A%0ALet%20me%20know%20if%20you%20want%20example%20code%20for%20conditional%20hashing/verification%20or%20migration%20strategies%21)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/6608)
Author
Owner

@bytaesu commented on GitHub (Feb 8, 2026):

Hi @n2k3,

Changing the default behavior could break compatibility for existing servers. Since the hashing algorithm can already be customized, it's better to keep the current approach.

<!-- gh-comment-id:3867303097 --> @bytaesu commented on GitHub (Feb 8, 2026): Hi @n2k3, Changing the default behavior could break compatibility for existing servers. Since the hashing algorithm can already be customized, it's better to keep the current approach.
Author
Owner

@github-actions[bot] commented on GitHub (Apr 1, 2026):

This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.

<!-- gh-comment-id:4166559267 --> @github-actions[bot] commented on GitHub (Apr 1, 2026): This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19200