[PR #5385] [CLOSED] Feat: add pattern option to validate password #5972

Closed
opened 2026-03-13 12:43:13 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5385
Author: @hieudien14310
Created: 10/17/2025
Status: Closed

Base: canaryHead: feat/add-pattern-option-to-validate-password


📝 Commits (10+)

  • f0652db feat: add custom password strength pattern option
  • 456a121 feat: add password pattern validation option
  • 36779b6 feat: add pattern property to password configuration
  • 0f43dcf feat: add password pattern option to email and password configuration
  • 8cf3af8 feat: add password pattern validation to sign-up and admin processes
  • 340cbfe feat: add password pattern validation logging in sign-up and admin processes
  • fd382f4 feat: add password pattern validation in changePassword endpoint
  • b6768bb feat: add password pattern validation in resetPassword and setPassword endpoints
  • 98c89a6 add password pattern validation tests for sign-up process
  • 6e6cfc8 refactor: remove console log from password pattern validation test

📊 Changes

13 files changed (+285 additions, -4 deletions)

View changed files

📝 docs/content/docs/reference/options.mdx (+3 -1)
📝 packages/better-auth/src/__snapshots__/init.test.ts.snap (+1 -0)
📝 packages/better-auth/src/api/routes/reset-password.ts (+10 -1)
📝 packages/better-auth/src/api/routes/sign-up.test.ts (+67 -0)
📝 packages/better-auth/src/api/routes/sign-up.ts (+13 -0)
📝 packages/better-auth/src/api/routes/update-user.test.ts (+67 -0)
📝 packages/better-auth/src/api/routes/update-user.ts (+17 -2)
📝 packages/better-auth/src/init.ts (+1 -0)
📝 packages/better-auth/src/plugins/admin/admin.test.ts (+85 -0)
📝 packages/better-auth/src/plugins/admin/admin.ts (+13 -0)
📝 packages/core/src/error/codes.ts (+1 -0)
📝 packages/core/src/types/context.ts (+1 -0)
📝 packages/core/src/types/init-options.ts (+6 -0)

📄 Description

Currently, I see that password are only being validated based on min and max length. That is not really comprehensive. So I added a feature to validate password using a pattern to make it stronger and more customizable.

I put the pattern configuration inside emailAndPassword. Once this pattern is set, it will affect all apis related to the password.
If you guys have any feedback, please comment. So I will fix it accordingly.


Summary by cubic

Add an optional regex pattern to enforce password strength across all email/password flows. This keeps passwords consistent and stronger in sign-up, reset, change, and admin actions.

  • New Features
    • emailAndPassword.pattern (RegExp, default: null) to validate passwords.
    • Enforced in sign-up, changePassword, setPassword, resetPassword, and admin setUserPassword; returns 400 BAD_REQUEST with code PASSWORD_NOT_VALID_PATTERN.
    • Added error code, logging, types, docs, and 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/5385 **Author:** [@hieudien14310](https://github.com/hieudien14310) **Created:** 10/17/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `feat/add-pattern-option-to-validate-password` --- ### 📝 Commits (10+) - [`f0652db`](https://github.com/better-auth/better-auth/commit/f0652db9f2883e93b755ff346aed9d3b2093da72) feat: add custom password strength pattern option - [`456a121`](https://github.com/better-auth/better-auth/commit/456a121850a2788c2f0cfcf9b78df9e6a48c5085) feat: add password pattern validation option - [`36779b6`](https://github.com/better-auth/better-auth/commit/36779b676c438df19ade67396ea6f55b139e25a8) feat: add pattern property to password configuration - [`0f43dcf`](https://github.com/better-auth/better-auth/commit/0f43dcfa370c335ff49a5e68856ee3b1771ec644) feat: add password pattern option to email and password configuration - [`8cf3af8`](https://github.com/better-auth/better-auth/commit/8cf3af8fac15da87e8fa04104f027a78ae7e559c) feat: add password pattern validation to sign-up and admin processes - [`340cbfe`](https://github.com/better-auth/better-auth/commit/340cbfe2dd219a6efc162fe1ac5253087e5fd72b) feat: add password pattern validation logging in sign-up and admin processes - [`fd382f4`](https://github.com/better-auth/better-auth/commit/fd382f43dab2775ca5a1e1edd48182d0fa5c7774) feat: add password pattern validation in changePassword endpoint - [`b6768bb`](https://github.com/better-auth/better-auth/commit/b6768bb671f35d6a8a4c1ccc2117636ff8544810) feat: add password pattern validation in resetPassword and setPassword endpoints - [`98c89a6`](https://github.com/better-auth/better-auth/commit/98c89a6d42cdec7017ed3ec0dbbba4ec4d8a4ebd) add password pattern validation tests for sign-up process - [`6e6cfc8`](https://github.com/better-auth/better-auth/commit/6e6cfc8384a03ef952011304a86ce9faa42531d4) refactor: remove console log from password pattern validation test ### 📊 Changes **13 files changed** (+285 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/reference/options.mdx` (+3 -1) 📝 `packages/better-auth/src/__snapshots__/init.test.ts.snap` (+1 -0) 📝 `packages/better-auth/src/api/routes/reset-password.ts` (+10 -1) 📝 `packages/better-auth/src/api/routes/sign-up.test.ts` (+67 -0) 📝 `packages/better-auth/src/api/routes/sign-up.ts` (+13 -0) 📝 `packages/better-auth/src/api/routes/update-user.test.ts` (+67 -0) 📝 `packages/better-auth/src/api/routes/update-user.ts` (+17 -2) 📝 `packages/better-auth/src/init.ts` (+1 -0) 📝 `packages/better-auth/src/plugins/admin/admin.test.ts` (+85 -0) 📝 `packages/better-auth/src/plugins/admin/admin.ts` (+13 -0) 📝 `packages/core/src/error/codes.ts` (+1 -0) 📝 `packages/core/src/types/context.ts` (+1 -0) 📝 `packages/core/src/types/init-options.ts` (+6 -0) </details> ### 📄 Description Currently, I see that password are only being validated based on min and max length. That is not really comprehensive. So I added a feature to validate password using a pattern to make it stronger and more customizable. I put the pattern configuration inside `emailAndPassword`. Once this pattern is set, it will affect all apis related to the password. If you guys have any feedback, please comment. So I will fix it accordingly. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add an optional regex pattern to enforce password strength across all email/password flows. This keeps passwords consistent and stronger in sign-up, reset, change, and admin actions. - New Features - emailAndPassword.pattern (RegExp, default: null) to validate passwords. - Enforced in sign-up, changePassword, setPassword, resetPassword, and admin setUserPassword; returns 400 BAD_REQUEST with code PASSWORD_NOT_VALID_PATTERN. - Added error code, logging, types, docs, and tests. <!-- End of auto-generated description by cubic. --> --- <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-03-13 12:43:13 -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#5972