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
- Variables
- func CheckPassword(password, username string) error
- func CheckUsername(u string) error
- func Hash(password string) (string, error)
- func HashToken(token string) string
- func NewSetupCode() (string, error)
- func NewToken() (token, hash string, err error)
- func SameCode(typed, real string) bool
- func Verify(password, encoded string) (ok, needsRehash bool)
- func VerifyNothing(password string)
Constants ¶
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).
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 ¶
var ErrWeakPassword = errors.New("password refused")
ErrWeakPassword wraps every policy refusal; its message says what to change.
Functions ¶
func CheckPassword ¶
CheckPassword applies the policy; the error says what to change.
func CheckUsername ¶
CheckUsername allows 3–64 letters, digits and . _ - @ (an e-mail address works).
func NewSetupCode ¶
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 ¶
NewToken returns a random session token (256 bits) and the hash under which it is stored.
func SameCode ¶
SameCode compares a typed setup code with the real one, ignoring case, spaces and dashes, in constant time.
func Verify ¶
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.