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

recoverycode

package
v1.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package recoverycode makes and checks 2FA recovery codes: single-use codes a user keeps for when they lose their authenticator.

Each code is 16 random base32 characters (80 bits), shown in groups of four. Codes are stored as SHA-256 hashes. That's enough: slow hashes like argon2 exist to resist guessing passwords that people choose, and an 80-bit random code can't be guessed either way (docs/api.md §8).

Index

Constants

View Source
const Count = 10

Count is how many codes a user gets.

Variables

This section is empty.

Functions

func Hash

func Hash(normalized string) []byte

Hash returns the hash to store for a normalized code.

func New

func New() []string

New returns Count new codes, formatted for display (XXXX-XXXX-XXXX-XXXX).

func Normalize

func Normalize(code string) (normalized string, ok bool)

Normalize returns code as stored before hashing: uppercase, without dashes or spaces, so users can type it loosely. ok is false if it can't be a recovery code.

Types

This section is empty.

Jump to

Keyboard shortcuts

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