Help us shape the future of Go! Take the 2026 Go Developer Survey

credentials

package
v0.3.3 Latest Latest
Warning

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

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

Documentation

Overview

Package credentials generates, hashes and verifies the secrets the application issues or accepts: passwords, API tokens, service credentials and recovery codes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateCollectKey

func GenerateCollectKey() (string, error)

GenerateCollectKey returns a per-workspace collect write-key (x-collect-key).

func GenerateIngestKey

func GenerateIngestKey() (string, error)

GenerateIngestKey returns an Integration's hook key (POST /hooks/{key}): the address of one Integration's inbound provider callbacks, which also names its Workspace. Unlike the collect key it is never exposed in the browser tracker.

func GenerateServiceCredential

func GenerateServiceCredential() (prefix, secret, value string, err error)

GenerateServiceCredential returns a new Service credential's visible prefix, its secret and the value a service presents (`smsc_<prefix>_<secret>`). The prefix of an API token is `omtk`, so one kind never parses as the other.

func GenerateTokenPrefix

func GenerateTokenPrefix() (string, error)

func GenerateTokenSecret

func GenerateTokenSecret() (string, error)

func HashPassword

func HashPassword(password string) (string, error)

HashPassword returns a PHC-encoded argon2id hash of the given password.

func HashRecoveryCode

func HashRecoveryCode(code string) string

HashRecoveryCode is the stored form of a Recovery code (ADR 0020): the SHA-256 hex of the code lower-cased with spaces and dashes removed, so it may be typed either way. The codes are random, so an unsalted fast hash is enough, and the lookup by hash must be deterministic.

func HashServiceSecret

func HashServiceSecret(secret string) string

HashServiceSecret is the stored form of a Service credential's secret: its SHA-256 hex. The secret is 40 random characters, so a fast unsalted hash is enough, and it is checked on every request, where a slow password hash would be a cost with no gain.

func HashTokenSecret

func HashTokenSecret(secret string) (string, error)

func ServiceCredentialValue

func ServiceCredentialValue(prefix, secret string) string

ServiceCredentialValue is the value a service presents for a credential.

func TokenValue

func TokenValue(prefix, secret string) string

func UseMinTokenHashCost

func UseMinTokenHashCost()

UseMinTokenHashCost lowers the cost of every secret hashed from now on to bcrypt's minimum. Only tests call it: at cost 12 each created token takes about 0.3s, which dominates a suite that creates one per request.

func VerifyPassword

func VerifyPassword(encodedHash, password string) bool

VerifyPassword reports whether password matches the PHC-encoded hash.

func VerifyServiceSecret

func VerifyServiceSecret(secret, hash string) bool

VerifyServiceSecret reports whether secret hashes to the stored hash, in constant time.

func VerifyTokenSecret

func VerifyTokenSecret(secret, hash string) bool

Types

type ParsedToken

type ParsedToken struct {
	Prefix string
	Secret string
}

func ParseServiceCredential

func ParseServiceCredential(value string) *ParsedToken

ParseServiceCredential splits a presented value into its prefix and secret; nil when the value is not shaped like a Service credential.

func ParseToken

func ParseToken(value string) *ParsedToken

Jump to

Keyboard shortcuts

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