token

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package token mints high-entropy random tokens and stores their sha256 hashes. The pattern: generate a random token, send it in URLs/emails, store only the hash. A DB dump leaks no usable tokens; lookups remain O(1) via a UNIQUE index on the hash column.

Index

Constants

View Source
const SizeBytes = 32

SizeBytes is the random payload length. 32 bytes (256 bits) is far beyond brute-force budgets for any plausible attacker. base64url-encoded it produces a 43-character ASCII-safe URL fragment.

Variables

This section is empty.

Functions

func Equal

func Equal(a, b []byte) bool

Equal compares two hashes in constant time. Use this instead of bytes.Equal anywhere a comparison's timing could leak information.

func HashOf

func HashOf(s string) ([]byte, error)

HashOf returns the sha256 of the raw bytes encoded in s. Used by lookup paths: parse the URL fragment, hash, query by hash.

func New

func New() (encoded string, hash []byte, err error)

New mints a fresh token. Returns the URL-safe encoding for inclusion in emails and links and the sha256 hash for storage in the DB.

Types

This section is empty.

Jump to

Keyboard shortcuts

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