[PR #5569] Fix(admin-user): Add min/max password length validation #31691

Open
opened 2026-04-17 22:34:51 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5569
Author: @hieudien14310
Created: 10/25/2025
Status: 🔄 Open

Base: mainHead: fix/check-min-and-max-password-length-for-admin-create-user


📝 Commits (10+)

  • 300924f feat(admin): add password length validation in user creation
  • 4239a48 feat(password): add minimum password length check and integrate into admin plugin
  • bc888e9 feat(password): replace min password check with comprehensive length validation
  • 7953db6 fix(password): set default value for password parameter in checkPasswordLength function
  • 1a04f9d update test user passwords for consistency in admin tests
  • 15e4d38 correct import path for BASE_ERROR_CODES and standardize password parameter default value
  • 8f194e9 update checkPasswordLength function
  • 4dc6314 Merge branch 'canary' into fix/check-min-and-max-password-length-for-admin-create-user
  • 9ee181c add checkPasswordLength function to password config in snapshot
  • 5a8280a Merge branch 'canary' into fix/check-min-and-max-password-length-for-admin-create-user

📊 Changes

6 files changed (+46 additions, -10 deletions)

View changed files

📝 packages/better-auth/src/__snapshots__/init.test.ts.snap (+1 -0)
📝 packages/better-auth/src/init.ts (+2 -1)
📝 packages/better-auth/src/plugins/admin/admin.test.ts (+9 -9)
📝 packages/better-auth/src/plugins/admin/admin.ts (+2 -0)
📝 packages/better-auth/src/utils/password.ts (+27 -0)
📝 packages/core/src/types/context.ts (+5 -0)

📄 Description

Summary by cubic

Enforces min/max password length when admins create users, preventing weak or overly long passwords. Adds a reusable length check and returns clear error codes.

  • Bug Fixes
    • Validate password length in admin.createUser using checkPasswordLength.
    • Expose checkPasswordLength on ctx.context.password; respects configured minPasswordLength and maxPasswordLength (max defaults to 128).
    • Return BAD_REQUEST with PASSWORD_TOO_SHORT or PASSWORD_TOO_LONG on violations.
    • Update admin tests to use compliant passwords.
    • Add types for checkPasswordLength and wire it in init.

🔄 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/5569 **Author:** [@hieudien14310](https://github.com/hieudien14310) **Created:** 10/25/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/check-min-and-max-password-length-for-admin-create-user` --- ### 📝 Commits (10+) - [`300924f`](https://github.com/better-auth/better-auth/commit/300924fc9a2f643f8b95387d5455d6a7c9cf0f64) feat(admin): add password length validation in user creation - [`4239a48`](https://github.com/better-auth/better-auth/commit/4239a4820d46f88bbc0e908467cbed963bdf9aab) feat(password): add minimum password length check and integrate into admin plugin - [`bc888e9`](https://github.com/better-auth/better-auth/commit/bc888e9f3b77701d0509e7e98ed5a11b4005a0c0) feat(password): replace min password check with comprehensive length validation - [`7953db6`](https://github.com/better-auth/better-auth/commit/7953db65b375fb0f6f9cc153ff97d35c1a8ad2f3) fix(password): set default value for password parameter in checkPasswordLength function - [`1a04f9d`](https://github.com/better-auth/better-auth/commit/1a04f9dd785f23e8b03cf23bdd784ec1a19a7098) update test user passwords for consistency in admin tests - [`15e4d38`](https://github.com/better-auth/better-auth/commit/15e4d385f135dea31bbb66ab5302b8ea29f1c270) correct import path for BASE_ERROR_CODES and standardize password parameter default value - [`8f194e9`](https://github.com/better-auth/better-auth/commit/8f194e96fec45c1f32f0c846de0548254e0915d7) update checkPasswordLength function - [`4dc6314`](https://github.com/better-auth/better-auth/commit/4dc631432face32ab2e208ed4cf9d87e538f0f47) Merge branch 'canary' into fix/check-min-and-max-password-length-for-admin-create-user - [`9ee181c`](https://github.com/better-auth/better-auth/commit/9ee181c2cd4bdff6264f98802a12a4bcf7fceb1b) add checkPasswordLength function to password config in snapshot - [`5a8280a`](https://github.com/better-auth/better-auth/commit/5a8280adbeb8f019e1edc1ec3c80dcca15f323cf) Merge branch 'canary' into fix/check-min-and-max-password-length-for-admin-create-user ### 📊 Changes **6 files changed** (+46 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/__snapshots__/init.test.ts.snap` (+1 -0) 📝 `packages/better-auth/src/init.ts` (+2 -1) 📝 `packages/better-auth/src/plugins/admin/admin.test.ts` (+9 -9) 📝 `packages/better-auth/src/plugins/admin/admin.ts` (+2 -0) 📝 `packages/better-auth/src/utils/password.ts` (+27 -0) 📝 `packages/core/src/types/context.ts` (+5 -0) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Enforces min/max password length when admins create users, preventing weak or overly long passwords. Adds a reusable length check and returns clear error codes. - **Bug Fixes** - Validate password length in admin.createUser using checkPasswordLength. - Expose checkPasswordLength on ctx.context.password; respects configured minPasswordLength and maxPasswordLength (max defaults to 128). - Return BAD_REQUEST with PASSWORD_TOO_SHORT or PASSWORD_TOO_LONG on violations. - Update admin tests to use compliant passwords. - Add types for checkPasswordLength and wire it in init. <!-- 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-04-17 22:34:51 -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#31691