genie

package module
v0.0.0-...-2400b50 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package genie provides utilities for generating various types of secure, cryptographically random identifiers and tokens including:

- Public IDs using nanoid with custom alphabet for URL-safe, collision-resistant identifiers - One-time passwords (OTPs) using base32 encoding for authentication codes - General-purpose tokens using base64 URL encoding - Session tokens with 256 bits of entropy using base32 encoding

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateOTP

func GenerateOTP() (string, error)

GenerateOTP creates a 6-character one-time password (OTP) using base32 encoding, suitable for short-lived authentication codes.

func GeneratePublicID

func GeneratePublicID() (string, error)

GeneratePublicID creates a URL-safe, collision-resistant public identifier using nanoid with a custom alphabet. Returns a 12-character string suitable for public-facing identifiers.

func GenerateSessionToken

func GenerateSessionToken() (string, error)

GenerateSessionToken creates a cryptographically secure session token with 256 bits of entropy using base32 encoding. The resulting token is 52 characters long and is case-insensitive, making it suitable for session management.

Returns a base32-encoded string representing 32 bytes of random data.

func GenerateToken

func GenerateToken(length int) (string, error)

GenerateToken creates a URL-safe random token of the specified length using base64 URL encoding, suitable for general-purpose secure tokens.

Note: This function truncates the encoded result to match the requested length, which may result in slightly reduced entropy compared to the raw bytes. For session tokens, use GenerateSessionToken instead.

func MustGeneratePublicID

func MustGeneratePublicID() string

MustGeneratePublicID creates a URL-safe public identifier and panics on error. Use this when you need a public ID and cannot handle errors gracefully.

Types

This section is empty.

Jump to

Keyboard shortcuts

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