ory/hydra · error
ErrBcryptPasswordLengthReached
ErrBcryptPasswordLengthReached
Error message
passwords are limited to a maximum length of 72 characters
What it means
ErrBcryptPasswordLengthReached is a sentinel error from ory/x hasherx returned by validateBcryptPasswordLength when a password exceeds 72 bytes, the bcrypt algorithm's hard input limit (bcrypt only uses the first 72 bytes). The hasher rejects the password up front instead of silently truncating it, so callers don't get a false sense of security.
Source
Thrown at oryx/hasherx/hasher_bcrypt.go:15
package hasherx
import (
"context"
"github.com/pkg/errors"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"golang.org/x/crypto/bcrypt"
"github.com/ory/x/otelx"
)
// ErrBcryptPasswordLengthReached is returned when the password is longer than 72 bytes.
var ErrBcryptPasswordLengthReached = errors.Errorf("passwords are limited to a maximum length of 72 characters")
type (
// Bcrypt is a hasher that uses the bcrypt algorithm.
Bcrypt struct {
c BCryptConfigurator
}
// BCryptConfig is the configuration for the bcrypt hasher.
BCryptConfig struct {
Cost uint32 `json:"cost"`
}
// BCryptConfigurator is the interface that must be implemented by a configuration provider for the bcrypt hasher.
BCryptConfigurator interface {
HasherBcryptConfig(ctx context.Context) *BCryptConfig
}
)
func NewHasherBcrypt(c BCryptConfigurator) *Bcrypt {
return &Bcrypt{c: c}View on GitHub (pinned to 4174065ffb)
Solutions
- Truncate or reject passwords longer than 72 bytes in your application's signup/password-change flow before hashing
- Enforce a maxLength=72 validation on password inputs in the UI and API
- Pre-hash long inputs with SHA-256 and base64-encode the digest before bcrypt if you must support arbitrary-length secrets
- Fall back to a hasher without the 72-byte limit (e.g. argon2id) if long passphrases are a requirement
Example fix
// before
hasher.GenerateHash(ctx, password) // panics/errors when len(password) > 72
// after
if len(password) > 72 {
return fmt.Errorf("password must be at most 72 characters")
}
hash, err := hasher.GenerateHash(ctx, password) Defensive patterns
Strategy: validation
Validate before calling
func validatePassword(pw string) error {
if len(pw) > 72 {
return fmt.Errorf("password must be at most 72 characters, got %d", len(pw))
}
return nil
} Try / catch
if err := hasher.GenerateHash(ctx, pw); errors.Is(err, hasherx.ErrBcryptPasswordLengthReached) {
// prompt user to choose a shorter password
} Prevention
- Enforce maxLength=72 on all password inputs (UI and API)
- Validate length before hashing, not after
- Remember the limit is bytes, not runes — multibyte characters count more
- Consider pre-hashing with SHA-256 if arbitrary-length secrets must be supported
When it happens
Trigger: Calling a Bcrypt hasher's GenerateHash/ComparePassword (which calls validateBcryptPasswordLength at hasher_bcrypt.go:60) with len(password) > 72.
Common situations: Users pasting long passphrases or generated secrets (SSH keys, JWTs, base64 blobs) as passwords; apps that don't enforce a max length on signup; switching from a hasher without a limit (e.g. argon2) to bcrypt.
Related errors
- Token is expired
- Token used before issued
- Token is not valid yet
- cookiex: purpose must be non-empty and must not contain a pi
- cookiex: max age must not be negative
AI-assisted analysis of ory/hydra@4174065ffb (2026-09-03).
Data as JSON: /api/errors/08f691a60fd4e04f.
Report an issue: GitHub.