Documentation
¶
Overview ¶
Package password implements argon2id password hashing with PHC-string encoding. argon2id is the OWASP-recommended scheme: memory-hard, parallelism-tunable, and the PHC-format winner.
Output format (matches the canonical PHC string):
$argon2id$v=19$m=65536,t=3,p=2$<saltB64>$<hashB64>
The b64 encoding is RFC4648 standard b64 *without* padding, per the PHC spec. Hashes produced here are forward-compatible: parameters travel inside the string so callers can rotate Defaults() without losing the ability to verify older hashes.
Index ¶
Constants ¶
const Algo = "argon2id-v1"
Algo is the password_algo column value for hashes produced by this package. Lets the DB carry an explicit identifier so we can roll forward to a different algorithm later without ambiguity.
const MinPasswordLength = 10
MinPasswordLength is the absolute floor enforced at the lowest layer. Higher layers (signup form) MAY enforce additional rules (common-password list, etc.) but MUST NOT relax this minimum.
Variables ¶
This section is empty.
Functions ¶
func Hash ¶
Hash produces a PHC-encoded argon2id string for password using p. Returns an error when password is shorter than MinPasswordLength so the policy floor cannot be bypassed by a misbehaving caller.
func MustGenerateDummy ¶
func MustGenerateDummy(p Params)
MustGenerateDummy generates the dummy hash on first call. Safe to call during init in test code; production wires this from server start so the hash matches the configured Params.
func Verify ¶
Verify reports whether password matches the PHC-encoded hash. Returns false (without error) for a mismatching password and an error for a malformed hash.
func VerifyAgainstDummy ¶
func VerifyAgainstDummy(password string)
VerifyAgainstDummy runs Verify against the pre-computed dummy hash. Used by login handlers when the user lookup fails so the response time matches a real Verify call.
Types ¶
type Params ¶
type Params struct {
Memory uint32 // KiB
Time uint32 // iterations
Threads uint8 // parallelism
SaltLen uint32 // bytes
KeyLen uint32 // bytes
}
Params controls argon2id cost. Defaults() values are tuned to take roughly 100–300ms on dev hardware (Apple M-series) and a similar envelope on the production droplet (modern x86, 4 vCPU). Operators can override via auth.argon2.* config.