JuliusBrussee/caveman · error
password must be at least
Error message
password must be at least %d bytes
What it means
ValidatePassword enforces the shared platform password policy: passwords must be at least MinPasswordBytes (12) bytes in length. The check uses raw byte length (len(password)), so multibyte UTF-8 characters count as multiple bytes. The error names the required minimum so callers can surface it directly to users.
Solutions
- Require the user to supply a password of at least 12 bytes before calling ValidatePassword or the API.
- Update password-generation logic to emit >= 12 bytes (e.g. 16+ random bytes base64).
- Fix UI/form minimum-length validation to match MinPasswordBytes so users get feedback before the API call.
- If you must accept shorter legacy values, migrate them: force a reset and store only policy-compliant passwords.
Example fix
// before
pw := r.FormValue("password") // "secret12"
if err := security.ValidatePassword(pw); err != nil { ... } // password must be at least 12 bytes
// after
pw := r.FormValue("password")
if len(pw) < security.MinPasswordBytes {
http.Error(w, fmt.Sprintf("password must be at least %d characters", security.MinPasswordBytes), http.StatusBadRequest)
return
}
if err := security.ValidatePassword(pw); err != nil { ... } Defensive patterns
Strategy: validation
Validate before calling
if len([]byte(password)) < security.MinPasswordBytes {
return fmt.Errorf("choose a password of at least %d characters", security.MinPasswordBytes)
} Type guard
func meetsMinLength(pw string) bool { return len(pw) >= security.MinPasswordBytes } Try / catch
if err := security.ValidatePassword(pw); err != nil {
if strings.Contains(err.Error(), "at least") {
return fmt.Errorf("password too weak: %v", err)
}
return err
} Prevention
- Mirror MinPasswordBytes in every client-side form validator.
- Generate passwords/keys at 16+ bytes so the floor is never brushed.
- Enforce the policy at account-creation and change-password endpoints alike.
- Force resets for legacy passwords shorter than the policy.
When it happens
Trigger: Calling ValidatePassword with a string whose byte length is < 12 — e.g. "hunter2", "Password1!" (10 chars), or a 12-character string of multibyte characters that would pass a character count but the check is on bytes so it actually passes — specifically any input under 12 bytes.
Common situations: User signup/login forms accepting short passwords before validation; generated passwords from an old policy; test fixtures with placeholder passwords; trimming a password to fit a legacy 8-char system.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- password must be at most
- arm must be or
- CAVEMAN_CCR_MAX_BYTES must be a positive integer
- ccr max storage bytes must be positive
- ccr: unknown lifecycle
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/328c8043736894e7.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/security/keys.go:22
"crypto/hmac"
"crypto/rand"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"fmt"
"strings"
"golang.org/x/crypto/argon2"
)
const (
MinPasswordBytes = 12
MaxPasswordBytes = 1024
)
func ValidatePassword(password string) error {
if len(password) < MinPasswordBytes {
return fmt.Errorf("password must be at least %d bytes", MinPasswordBytes)
}
if len(password) > MaxPasswordBytes {
return fmt.Errorf("password must be at most %d bytes", MaxPasswordBytes)
}
return nil
}
func GenerateProjectKey() (string, string, error) {
raw := make([]byte, 32)
if _, err := rand.Read(raw); err != nil {
return "", "", err
}
secret := base64.RawURLEncoding.EncodeToString(raw)
full := "cave_live_" + secret[:12] + "_" + secret[12:]
return full, secret[:12], nil
}
func HashProjectKey(pepper, full string) string {View on GitHub (pinned to 3ee70a1026)