hotp

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package hotp implements the HMAC-based One-Time Password (HOTP) algorithm. It provides functionalities to generate codes, validate passcodes, and generate new HOTP keys representing "otpauth" URLs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(opts ...otp.Option) (*otp.Key, error)

Generate creates a new HOTP key containing a secret, issuer, and account name. The secret is either provided via the configuration options or securely generated using a cryptographic random number generator. It returns an *otp.Key, which can be formatted as an "otpauth://hotp/..." URL suitable for QR code generation.

func GenerateCode

func GenerateCode(secret string, counter uint64, opts ...otp.Option) (string, error)

GenerateCode generates an HOTP passcode using the provided base32-encoded secret, a counter, and optional configurations. It supports multiple encoders, including the default numerical encoder and a Steam-specific alphanumeric encoder. It returns the generated passcode as a string, or an error if the secret is invalid.

func Validate

func Validate(passcode string, counter uint64, secret string, opts ...otp.Option) (bool, error)

Validate checks whether the provided passcode is valid for the given counter and base32-encoded secret. It uses a constant-time comparison to protect against timing attacks. It returns true if the passcode matches, and false otherwise.

Types

This section is empty.

Jump to

Keyboard shortcuts

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