auth

package
v0.0.0-...-bd25097 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: AGPL-3.0 Imports: 14 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 hashes and verifies web passwords with argon2id (D8: passwords are for the web only; git over SSH uses keys and git over HTTPS uses tokens).

Index

Constants

This section is empty.

Variables

View Source
var ErrMismatch = errors.New("password mismatch")

ErrMismatch is returned by Verify when the password is wrong.

Functions

func Hash

func Hash(password string, p Params) (string, error)

Hash returns a PHC-formatted string: $argon2id$v=19$m=..,t=..,p=..$salt$hash. The parameters travel with the hash so cost can be raised later without a migration.

func NeedsRehash

func NeedsRehash(encoded string, p Params) bool

NeedsRehash reports whether a stored hash uses weaker parameters than p.

func NewRecoveryCode

func NewRecoveryCode() (string, error)

NewRecoveryCode returns one recovery code: 10 base32 characters in two groups ("abcde-fghij"), 50 random bits.

func NewTOTPSecret

func NewTOTPSecret() (string, error)

NewTOTPSecret returns a fresh secret as base32.

func NormalizeRecovery

func NormalizeRecovery(s string) string

NormalizeRecovery makes a typed recovery code comparable: lower case, no spaces or dashes.

func TOTPCode

func TOTPCode(secret string, step int64) (string, error)

TOTPCode is the code for one time step.

func TOTPStep

func TOTPStep(t time.Time) int64

TOTPStep is the time step a moment falls in.

func TOTPURI

func TOTPURI(issuer, account, secret string) string

TOTPURI is the otpauth:// link an authenticator app reads from the QR code.

func Verify

func Verify(password, encoded string) error

Verify checks password against a Hash output in constant time.

func VerifyTOTP

func VerifyTOTP(secret, code string, now time.Time, skew int, lastStep int64) (int64, bool)

VerifyTOTP checks a code against the steps around now (±skew) and returns the step it matched. A step at or before lastStep is refused, so a code that already signed someone in cannot be replayed.

Types

type Params

type Params struct {
	Time    uint32
	Memory  uint32 // KiB
	Threads uint8
}

Params are the argon2id cost parameters, taken from config.toml auth.

Jump to

Keyboard shortcuts

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