auth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 18 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 credential primitives: password hashing, random tokens and the one-time setup token.

Index

Constants

View Source
const MinPasswordLen = 12
View Source
const SetupTokenTTL = time.Hour

SetupTokenTTL is how long the one-time setup token printed at install stays valid (§5.0).

View Source
const TempKeyPrefix = "SYNAS"

TempKeyPrefix starts the key IDs of temporary credentials (STS).

Variables

View Source
var ErrWeakPassword = fmt.Errorf("password must be at least %d characters", MinPasswordLen)

Functions

func CheckSetupToken

func CheckSetupToken(ctx context.Context, st *store.Store, token string, now time.Time) (bool, error)

CheckSetupToken reports whether token is the current, unexpired setup token.

func EnsureSetupToken

func EnsureSetupToken(ctx context.Context, st *store.Store, now time.Time) (string, error)

EnsureSetupToken issues a fresh setup token if no account exists yet. It returns the plain token (to print once) or "" when setup is already done. A new token is issued on every controller start until setup completes, so a lost or expired token is recovered by restarting the controller.

func HashPassword

func HashPassword(password string) (string, error)

HashPassword returns a PHC-format argon2id hash.

func HashToken

func HashToken(token string) string

HashToken is how tokens are stored: never in plain text.

func NewAccessKey

func NewAccessKey() (id, secret string)

NewAccessKey returns a new access key ID ("SYNAK" + 16 chars) and secret (40 chars).

func NewID

func NewID(prefix string) string

NewID returns a short random identifier for database rows.

func NewTOTPSecret

func NewTOTPSecret() string

NewTOTPSecret returns a random 160-bit secret, base32 encoded.

func NewToken

func NewToken(prefix string) string

NewToken returns a random token with the given prefix, e.g. "syn_sess_…". 20 random bytes = 160 bits of entropy.

func NewUserCode

func NewUserCode() string

NewUserCode is a short code a person types to approve a device login: two groups of four letters without ambiguous ones (XXXX-XXXX).

func TOTPCode

func TOTPCode(secret string, t time.Time) (string, error)

TOTPCode returns the code for t (for tests and enrollment checks).

func TOTPURI

func TOTPURI(secret, issuer, account string) string

TOTPURI is the otpauth:// URI authenticator apps scan as a QR code.

func TokenMatches

func TokenMatches(token, storedHash string) bool

TokenMatches compares a presented token with a stored hash in constant time.

func VerifyPassword

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

VerifyPassword checks password against a hash produced by HashPassword, using the parameters stored in the hash.

func VerifyTOTP

func VerifyTOTP(secret, code string, t time.Time) bool

VerifyTOTP accepts the code of the current step or one step either side (clock skew).

Types

This section is empty.

Jump to

Keyboard shortcuts

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