totp

package module
v0.0.0-...-fb7470b Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2021 License: MIT Imports: 13 Imported by: 0

README

TOTP Authenticator

Generate example

t := totp.New()

uri, err := t.Generate(totp.Label{
  Issuer:      "Issuer.com",
  AccountName: "test@example.com",
})

secret := uri.Secret()             // UY346VGBYX4ELCZPCKHGKDFM6FVJEGLX
str := uri.String()                // otpauth://totp/Issuer.com:test@example.com?algorithm=SHA1&digits=6&issuer=Issuer.com&period=30&secret=UY346VGBYX4ELCZPCKHGKDFM6FVJEGLX
image, err = uri.Image(256)        // Convert []byte
err = uri.WriteFile(256, "qrcode") // qrcode.png

Validate Code

ok := t.Validate(123456, "UY346VGBYX4ELCZPCKHGKDFM6FVJEGLX")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Algorithm

type Algorithm string
const (
	SHA1   Algorithm = "SHA1"
	SHA256 Algorithm = "SHA256"
)

func (Algorithm) Hash

func (a Algorithm) Hash() hash.Hash

func (Algorithm) String

func (a Algorithm) String() string

type Calculator

type Calculator interface {
	Generate(l Label) (*uri, error)
	Validate(pin int, secret string) bool
}

func New

func New() Calculator

func NewWithOpts

func NewWithOpts(digits, period int, algorithm Algorithm) Calculator

type Label

type Label struct {
	Issuer      string // required
	AccountName string // required
	Secret      []byte // optional
	SecretSize  uint   // optional default: 20
}

Jump to

Keyboard shortcuts

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