otp

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 1, 2023 License: BSD-3-Clause Imports: 5 Imported by: 0

README

otp2go

Version License

Simple OTP library for Go

License: BSD-3-Clause

Usage

At a glance
// ...
import (
    "fmt"
    "crypto"
    _ "crypto/sha1"

    otp "github.com/chardon55/otp2go"
)
// ...
totp, err := otp.NewTOTPBase32("<Your Base32 secret>", crypto.SHA1)
// check error

password, remainTime := totp.GenerateString6()
fmt.Printf("Password: %s, remaining seconds: %d", password, remainTime)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HOTP

type HOTP interface {

	// Set counter
	SetCounter(uint64)

	// Generate an HOTP password
	Generate(digitCount uint8) uint32

	// Generate an HOTP password as a string
	GenerateString(digitCount uint8) string

	// Generate a 4-digit HOTP password
	Generate4() uint32

	// Generate a 4-digit HOTP password as a string
	GenerateString4() string

	// Generate a 6-digit HOTP password
	Generate6() uint32

	// Generate a 6-digit HOTP password as a string
	GenerateString6() string

	// Generate an 8-digit HOTP password
	Generate8() uint32

	// Generate an 8-digit HOTP password as a string
	GenerateString8() string
}

HOTP interface

func NewHOTP

func NewHOTP(secret []byte, algorithm crypto.Hash) HOTP

func NewHOTPBase32

func NewHOTPBase32(base32Secret string, algorithm crypto.Hash) (HOTP, error)

type TOTP

type TOTP interface {

	// Get interval
	Interval() uint32

	// Set interval
	SetInterval(uint32)

	// Generate a TOTP password
	Generate(digitCount uint8) (uint32, int)

	// Generate a TOTP password as a string
	GenerateString(digitCount uint8) (string, int)

	// Generate a 4-digit HOTP password
	Generate4() (uint32, int)

	// Generate a 4-digit HOTP password as a string
	GenerateString4() (string, int)

	// Generate a 6-digit HOTP password
	Generate6() (uint32, int)

	// Generate a 6-digit HOTP password as a string
	GenerateString6() (string, int)

	// Generate an 8-digit HOTP password
	Generate8() (uint32, int)

	// Generate an 8-digit HOTP password as a string
	GenerateString8() (string, int)
}

TOTP interface

func NewTOTP

func NewTOTP(secret []byte, algorithm crypto.Hash) TOTP

func NewTOTPBase32

func NewTOTPBase32(base32Secret string, algorithm crypto.Hash) (TOTP, error)

Jump to

Keyboard shortcuts

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