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

hash

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package hash derives and verifies password and token hashes with argon2id.

Used for local user passwords (R-042). API token secrets were hashed here too until issue #93; they are now HMAC-SHA-256 under a key outside the database (internal/core/tokenkey), and Verify still reads a token stored before that, once, before it is rewritten. Kept out of core so adapters may use it without importing anything the R-027 boundary forbids.

Index

Constants

View Source
const (
	GeneratedMin = 18
	GeneratedMax = 22
)

GeneratedMin and GeneratedMax bound a generated password's length. The length itself is random within them, so the length says nothing either.

View Source
const MinPasswordLength = 10

MinPasswordLength is the only rule a password has to satisfy.

Here rather than beside any one of its callers because there are three — the API's self-service change, first-run bootstrap, and the reset command — and three copies of a number is three chances for one of them to drift low. The number itself is [P], and the reasoning is in design 04 §2.7: no composition classes, because a class requirement produces `Passw0rd!`, which has less real entropy than three words and is the password the rule reliably produces.

A DR bundle's passphrase is longer (sixteen, design 07 D) and that difference is deliberate: a password is guessed against a server that rate-limits and can lock the account, and a passphrase protects a file an attacker already holds and can grind offline as fast as their hardware allows.

Variables

This section is empty.

Functions

func Generate

func Generate() (secret.Value, error)

Generate returns a password nobody chose: 18 to 22 characters from upper and lower case letters, digits and symbols, with at least one of each.

The one generator in Pando. First run's reset command, an administrator creating an account and an administrator resetting one all come here, so they cannot drift apart in length or alphabet — two generators eventually would, and the weaker one would be the one nobody looked at.

"At least one of each" is met by drawing again rather than by placing one of each at a chosen position, which would make those positions predictable. At 18+ characters from 80 symbols a draw missing a class is rare, so this almost never loops.

func New

func New(v secret.Value) (string, error)

New derives an encoded hash of v in the standard argon2 string format.

func Verify

func Verify(v secret.Value, encoded string) (bool, error)

Verify reports whether v matches the encoded hash.

The comparison is constant time. A malformed hash returns false with an error rather than panicking, because a corrupted row must deny access, not crash the login path.

Types

This section is empty.

Jump to

Keyboard shortcuts

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