totp

package module
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 20 Imported by: 1

README

go-totp

Installation

Use go get

go get -u github.com/FuLygon/go-totp

Import package

import "github.com/FuLygon/go-totp"

Example

See Example

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyIssuer issue value was required
	ErrEmptyIssuer = errors.New("issuer cannot be empty")
	// ErrEmptyAccountName account name value required
	ErrEmptyAccountName = errors.New("account name cannot be empty")
	// ErrInvalidAlgorithm invalid or unsupported algorithm
	ErrInvalidAlgorithm = errors.New("invalid or unsupported algorithm")
	// ErrInvalidDigits invalid or unsupported digits, supported value are 6 and 8
	ErrInvalidDigits = errors.New("invalid or unsupported digits")
	// ErrInvalidPeriod invalid period value
	ErrInvalidPeriod = errors.New("period cannot be empty")
	// ErrInvalidSecret invalid secret value
	ErrInvalidSecret = errors.New("secret is not a valid base32")
)

Functions

This section is empty.

Types

type Algorithm

type Algorithm string
const (
	AlgorithmSHA1   Algorithm = "SHA1"
	AlgorithmSHA256 Algorithm = "SHA256"
	AlgorithmSHA512 Algorithm = "SHA512"
)

type QR

type QR struct {
	Base64 string
	Image  image.Image
}

type TOTP

type TOTP struct {
	Algorithm   Algorithm
	Digits      uint8
	Period      uint64
	Issuer      string
	AccountName string
	Secret      string
}

func Generate

func Generate(issuer, accountName string, algorithm Algorithm, digits uint8, period uint64) (totp TOTP, err error)

func (TOTP) GetQR

func (t TOTP) GetQR(size int, qrRecoveryLevel ...qrcode.RecoveryLevel) (QR, error)

func (TOTP) GetURL

func (t TOTP) GetURL() (string, error)

type Validator

type Validator struct {
	Algorithm Algorithm
	Digits    uint8
	Period    uint64
	Secret    string
}

func (Validator) Validate

func (v Validator) Validate(code string) (bool, error)

func (Validator) ValidateWithTimestamp

func (v Validator) ValidateWithTimestamp(code string, timestamp int64) (bool, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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