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

credentials

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: AGPL-3.0 Imports: 10 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)

GenerateTokenSecret returns secretLen URL-safe base64 characters. secretLen is a multiple of 4, so the random bytes fill every character and the last one carries no zero padding bits.

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 HashSecret

func HashSecret(secret string) string

HashSecret is the stored form of a generated secret: its SHA-256 hex. The secret is 240 random bits, 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 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 VerifyPassword

func VerifyPassword(encodedHash, password string) bool

VerifyPassword reports whether password matches the PHC-encoded hash.

func VerifySecret

func VerifySecret(secret, hash string) bool

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

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