Help us shape the future of Go! Take the 2026 Go Developer Survey

password

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

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

View Source
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.

View Source
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

func Hash(password string, p Params) (string, error)

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

func Verify(password, encoded string) (bool, error)

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.

func Defaults

func Defaults() Params

Defaults returns the OWASP-recommended baseline. ~64 MiB memory, 3 iterations, 2 lanes — empirically ~100–300 ms on dev hardware.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL