crypto/password package provides a KDF-agnostic Encoder interface and
a DelegatingEncoder that tags each stored hash with an {id} algorithm
prefix, so multiple algorithms can coexist in the same password column.
Import
Encoder interface
Matches must run in constant time to resist timing attacks.
DelegatingEncoder
Routes encode/verify calls to the right algorithm based on the{id} prefix.
Legacy unprefixed hashes
For a column with unprefixed bcrypt hashes (predating the{id} prefix convention):
{bcrypt} prefix.
No re-hashing migration job required.
Registering a custom encoder
BcryptEncoder
DefaultBcryptCost is 10 — a widely-used baseline that balances hashing time
against brute-force resistance. A cost outside bcrypt’s valid range falls back
to the default.
Argon2idEncoder
m=65536 (64 MiB), t=3 iterations, p=2 threads.
Override any of them with functional options:
NoopEncoder
Choosing an algorithm
Encoding a new password
hash in your users.password_hash column.