otp

package
v0.0.0-...-573cd7b Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPasswordUsed = errors.New("the provided password has already been used")

Functions

func CleanUsedTOTP

func CleanUsedTOTP(password string)

CleanUsedTOTP will clear any recorded used TOTP that matches the given string.

func CleanUsedTOTPs

func CleanUsedTOTPs(age time.Duration)

CleanUsedTOTPs will clear all recorded used TOTPs that are older than the given age duration.

func NewKey

func NewKey(r io.Reader, alg Algorithm) ([]byte, error)

NewKey will use the given reader to generate some random bytes to be used as the key in a one time password.

Because of this it's important that the reader be set to nil in a production environment so that internally the function can use the most secure option which will be the standard library's crypto/rand reader.

Types

type Algorithm

type Algorithm int
const (
	Invalid Algorithm = iota
	SHA1
	SHA512
)

func NewAlgorithm

func NewAlgorithm(algorithm string) (Algorithm, error)

func (Algorithm) String

func (a Algorithm) String() string

type HMACBased

type HMACBased struct {
	// contains filtered or unexported fields
}

HMACBased implements an "HMAC-based One Time Password" (HOTP) in accordance with RFC4226 and any errata.

func NewHMACBased

func NewHMACBased(digits int, alg Algorithm) (HMACBased, error)

func (HMACBased) Generate

func (otp HMACBased) Generate(key []byte, count uint64) (string, error)

type TimeBased

type TimeBased struct {
	// contains filtered or unexported fields
}

TimeBased implements a "Time-based One Time Password" (TOTP) in accordance with RFC6238 and any errata.

func NewTimeBased

func NewTimeBased(digits int, alg Algorithm, baseTime time.Time, timeStep time.Duration) (TimeBased, error)

func (TimeBased) Check

func (otp TimeBased) Check(key []byte, t time.Time, delaySteps int, userPassword string) (bool, error)

func (TimeBased) Generate

func (otp TimeBased) Generate(key []byte, t time.Time) (string, error)

Jump to

Keyboard shortcuts

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