Skip to main content

Password Policy

Configure password strength requirements for user sign-up, password changes, and password resets.

Configuration

// edgebase.config.ts
export default defineConfig({
auth: {
passwordPolicy: {
minLength: 10, // Default: 8
requireUppercase: true, // Default: false
requireLowercase: true, // Default: false
requireNumber: true, // Default: false
requireSpecial: true, // Default: false
checkLeaked: true, // Default: false
},
},
});

Policy Options

OptionTypeDefaultDescription
minLengthnumber8Minimum password length
requireUppercasebooleanfalseRequire at least one uppercase letter (A-Z)
requireLowercasebooleanfalseRequire at least one lowercase letter (a-z)
requireNumberbooleanfalseRequire at least one digit (0-9)
requireSpecialbooleanfalseRequire at least one special character
checkLeakedbooleanfalseCheck against the Have I Been Pwned database

Enforcement Points

Password policy is validated at three endpoints:

  1. Sign-upPOST /auth/signup
  2. Password changePOST /auth/change-password
  3. Password resetPOST /auth/reset-password

When validation fails, the response includes all violated rules:

{
"error": "Password validation failed",
"details": {
"errors": [
"Password must be at least 10 characters.",
"Password must contain at least one uppercase letter.",
"Password must contain at least one special character."
]
}
}

Leaked Password Detection (HIBP)

When checkLeaked is enabled, passwords are checked against the Have I Been Pwned database using the k-anonymity model:

  1. The password is SHA-1 hashed
  2. Only the first 5 characters of the hash are sent to the HIBP API
  3. The server checks the response locally for a match

Privacy

  • The full password hash is never sent to HIBP
  • The k-anonymity model ensures HIBP cannot determine which password is being checked

Fail-Open Behavior

The HIBP check has a 3-second timeout and uses a fail-open policy:

  • If the HIBP API is unreachable or times out, the password is allowed
  • The check only runs after all other policy rules pass (to avoid unnecessary API calls)
  • Network errors do not block user sign-up or password changes

Password Hashing

EdgeBase uses PBKDF2-SHA256 with the following parameters:

ParameterValue
AlgorithmPBKDF2
Hash functionSHA-256
Iterations600,000 (OWASP 2023)
Salt128-bit (16 bytes), random
Key length256-bit (32 bytes)
Formatpbkdf2:sha256:600000:{salt_b64}:{hash_b64}

Legacy Hash Support

For users imported from other systems, EdgeBase also supports verifying bcrypt hashes ($2a$, $2b$, $2y$). Bcrypt passwords are automatically re-hashed to PBKDF2 on the user's next successful sign-in (lazy re-hash).

  • Email & Password — Sign-up, sign-in, password change, and reset flows
  • Auth HooksbeforePasswordReset hook for custom password policy enforcement
  • Limits — Password-related limits and defaults