auth

package
v0.7.12 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package auth holds the pieces of logging in that do not depend on the web: password hashing, one-time codes and recovery codes.

Index

Constants

View Source
const MinPasswordLength = 10

MinPasswordLength follows NIST SP 800-63B for passwords used together with a second factor.

Variables

This section is empty.

Functions

func CheckPassword

func CheckPassword(hash, pw string) bool

CheckPassword reports whether pw matches the hash. It reads the parameters from the hash, so older hashes keep working if the defaults change.

func CheckPasswordRules

func CheckPasswordRules(pw string) *msg.Error

func CheckSFTPPassword added in v0.7.4

func CheckSFTPPassword(hash, pw string) bool

CheckSFTPPassword is CheckPassword on the pool kept for SFTP.

func CheckTOTP

func CheckTOTP(secret []byte, code string, now time.Time) (step int64, ok bool)

CheckTOTP looks for code in the current time step and one step either side, to allow for clocks that are slightly off. It returns the step that matched, which the caller stores so the same code cannot be used twice.

func DummyCheck

func DummyCheck(pw string)

DummyCheck costs as much as CheckPassword. It is used when an account does not exist, so response times do not tell who has one.

func DummySFTPCheck added in v0.7.4

func DummySFTPCheck(pw string)

DummySFTPCheck is DummyCheck on the pool kept for SFTP.

func HashPassword

func HashPassword(pw string) string

HashPassword returns an argon2id hash in the PHC string format.

func HashRecoveryCode

func HashRecoveryCode(code string) []byte

HashRecoveryCode ignores case, spaces and dashes, since people type these by hand.

func NewRecoveryCodes

func NewRecoveryCodes() (codes []string, hashes [][]byte)

NewRecoveryCodes returns codes such as "k7m2p-x9qfa" and the hashes to store.

func NewTOTPSecret

func NewTOTPSecret() []byte

NewTOTPSecret returns a random 160-bit secret, as RFC 4226 recommends.

func TOTPCode added in v0.2.6

func TOTPCode(secret []byte, step int64) string

TOTPCode is the code an authenticator app shows in a time step, for tools that log in the way a person would.

func TOTPSecretText

func TOTPSecretText(secret []byte) string

TOTPSecretText is the secret for typing into an app by hand.

func TOTPURI

func TOTPURI(secret []byte, issuer, account string) string

TOTPURI is what the QR code holds, so an authenticator app can add the account in one scan.

Types

type Pool added in v0.7.4

type Pool struct {
	// contains filtered or unexported fields
}

Pool limits how many hashes run at once. SFTP checks have a pool of their own, so guessing at SFTP passwords cannot hold up logging in to the panel.

func NewPool added in v0.7.4

func NewPool(n int) *Pool

Jump to

Keyboard shortcuts

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