auth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package auth holds the decisions behind signing in (ADR-0018): how a password is hashed and checked, what a password must be, and how session tokens and setup codes are made. It has no state and no I/O; internal/store keeps the accounts and internal/server enforces the rules.

Index

Constants

View Source
const (
	MinPasswordLen = 12
	MaxPasswordLen = 256
)

Password limits (NIST SP 800-63B §3.1.1: a length floor, a generous ceiling, no composition rules, and a check against commonly used passwords).

View Source
const (
	Iterations = 600_000
)

PBKDF2-HMAC-SHA256 with the iteration count OWASP's Password Storage Cheat Sheet gives for it (600,000), a 16-byte random salt and a 32-byte key. It is in Go's standard library and FIPS 140-approved, so it needs no new module (the rule in CONTRIBUTING).

Variables

View Source
var ErrWeakPassword = errors.New("password refused")

ErrWeakPassword wraps every policy refusal; its message says what to change.

Functions

func CheckPassword

func CheckPassword(password, username string) error

CheckPassword applies the policy; the error says what to change.

func CheckUsername

func CheckUsername(u string) error

CheckUsername allows 3–64 letters, digits and . _ - @ (an e-mail address works).

func Hash

func Hash(password string) (string, error)

Hash returns the encoded hash of a password: scheme$iterations$salt$key.

func HashToken

func HashToken(token string) string

HashToken is how a session token is looked up: only its SHA-256 is stored.

func NewSetupCode

func NewSetupCode() (string, error)

NewSetupCode returns a one-time code for first-run setup: 12 characters from an alphabet without look-alikes, grouped for reading off a console (about 60 bits).

func NewToken

func NewToken() (token, hash string, err error)

NewToken returns a random session token (256 bits) and the hash under which it is stored.

func SameCode

func SameCode(typed, real string) bool

SameCode compares a typed setup code with the real one, ignoring case, spaces and dashes, in constant time.

func Verify

func Verify(password, encoded string) (ok, needsRehash bool)

Verify reports whether password matches the encoded hash, in constant time for the key comparison. needsRehash is true when the hash was made with weaker parameters than today's.

func VerifyNothing

func VerifyNothing(password string)

VerifyNothing spends the time a real check would.

Types

This section is empty.

Jump to

Keyboard shortcuts

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