Documentation
¶
Overview ¶
Package authn implements sign-in primitives: argon2id password hashing, opaque session and API tokens (only SHA-256 hashes are stored), TOTP, recovery codes, the optional breached-password check, passkeys and OIDC.
Index ¶
- Constants
- Variables
- func EqualHash(a, b []byte) bool
- func GroupSecret(secret string) string
- func HashPassword(password string) (string, error)
- func HashToken(token string) []byte
- func LooksLikeAPIKey(s string) bool
- func MaskAPIKey(key string) string
- func NeedsRehash(encoded string) bool
- func NewAPIKey(prefix string) (key string, hash []byte, masked string)
- func NewRecoveryCodes(n int) []string
- func NewToken() (token string, hash []byte)
- func NormalizeRecoveryCode(s string) string
- func PasswordProblem(password string, minLength int) string
- func VerifyDummy(password string)
- func VerifyPassword(password, encoded string) (bool, error)
- func VerifyTOTP(secret, code string, now time.Time) bool
- type BreachChecker
- type TOTPSecret
Constants ¶
const ( APIKeyPrefix = "rc_live_" AgentPrefix = "rc_agent_" )
Prefixes of API keys and MCP agent tokens.
Variables ¶
var ErrInvalidHash = errors.New("authn: invalid password hash")
ErrInvalidHash is returned for a malformed stored hash.
Functions ¶
func GroupSecret ¶
GroupSecret formats a secret for manual entry: "JBSW Y3DP EHPK 3PXP".
func HashPassword ¶
HashPassword returns a PHC-formatted argon2id hash.
func HashToken ¶
HashToken returns the SHA-256 of a token. Tokens carry 256 bits of entropy, so a fast hash is enough (no salt or KDF needed).
func LooksLikeAPIKey ¶
LooksLikeAPIKey reports whether a bearer token has an API key or agent prefix.
func MaskAPIKey ¶
MaskAPIKey shows the prefix, the first 4 and the last 4 characters.
func NeedsRehash ¶
NeedsRehash reports whether a hash was made with weaker parameters.
func NewAPIKey ¶
NewAPIKey returns a new key such as rc_live_8f2c…a91d (64 hex chars after the prefix), its hash, and the masked form shown in lists.
func NewRecoveryCodes ¶
NewRecoveryCodes returns n one-time codes formatted "b4xk-9q2m-7hdn".
func NewToken ¶
NewToken returns a random URL-safe token (32 bytes of entropy) and its SHA-256 hash. Only the hash is stored; the token goes to the client once.
func NormalizeRecoveryCode ¶
NormalizeRecoveryCode lower-cases and strips spaces so pasted codes match.
func PasswordProblem ¶
PasswordProblem explains why a password is rejected, or "" when it's fine.
func VerifyDummy ¶
func VerifyDummy(password string)
VerifyDummy burns the same time as a real verification.
func VerifyPassword ¶
VerifyPassword reports whether password matches the stored hash, in constant time.
Types ¶
type BreachChecker ¶
BreachChecker asks the Have I Been Pwned range API whether a password is known from breaches. Only the first five hex characters of the SHA-1 leave the server (k-anonymity). Instance admins can turn it off for offline installs.
func NewBreachChecker ¶
func NewBreachChecker() *BreachChecker
NewBreachChecker returns a checker with a short timeout.
type TOTPSecret ¶
type TOTPSecret struct {
Secret string // base32, no padding
URL string // otpauth:// URL for the QR code
}
TOTPSecret holds a freshly generated authenticator secret.
func NewTOTP ¶
func NewTOTP(issuer, account string) (TOTPSecret, error)
NewTOTP generates a secret for the given issuer (instance name) and account.