token

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package token generates and hashes the random secrets used for sessions, email verification, and password resets.

A token is handed to the client exactly once. Only its SHA-256 hash is stored, so a database leak doesn't expose working tokens.

Index

Constants

View Source
const Size = 32

Size is the number of random bytes in a token.

Variables

This section is empty.

Functions

func Equal

func Equal(a, b []byte) bool

Equal reports whether two hashes are equal, in constant time.

func Hash

func Hash(token string) []byte

Hash returns the SHA-256 hash of a token, for storage and lookup.

func New

func New() string

New returns a new random token: Size bytes from crypto/rand, encoded as unpadded base64url so it's safe in headers, cookies, and URLs.

func Valid

func Valid(s string) bool

Valid reports whether s has the exact shape of a token from New. It lets callers reject garbage input before doing a database lookup.

Types

This section is empty.

Jump to

Keyboard shortcuts

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