otp

package
v0.0.0-...-043c17a Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValid

func IsValid(secret, code string, period uint, digits int, algorithm Algorithm) (bool, error)

OTP Code Valid secret: base32 encoded secret key code: OTP code period: time period digits: number of digits algorithm: hash algorithm

func NewHOTP

func NewHOTP(key []byte, counter int64, digits int, algorithm Algorithm) string

HOTP: An HMAC-Based One-Time Password Algorithm https://datatracker.ietf.org/doc/html/rfc4226 HOTP(K,C) = Truncate(HMAC-SHA-1(K,C))

func NewTOTP

func NewTOTP(secret string, period uint, digits int, algorithm Algorithm) (string, error)

TOTP: Time-Based One-Time Password Algorithm https://datatracker.ietf.org/doc/html/rfc6238 TOTP(K,T) = HOTP(K,C)

func Verify

func Verify(secret, code string, period uint, digits int) (bool, error)

Types

type Algorithm

type Algorithm int
const (
	// SHA1 is the default hash algorithm used by Google Authenticator
	SHA1 Algorithm = iota
	// SHA256 is the hash algorithm used by Google Authenticator
	SHA256
	// SHA512 is the hash algorithm used by Google Authenticator
	SHA512
)

type GoogleOTP

type GoogleOTP struct {
	Secret     string
	OtpAuthURL string
	Digits     int
	Algorithm  Algorithm
	QrCodeURL  string
}

Google One-Time Password

func NewGoogleOTP

func NewGoogleOTP(key, issuer, accountName string, digits int) (GoogleOTP, error)

New One-time Password For Google Authenticator key: the seed of base32 encoded secret key issuer: the issuer of the account accountName: the name of the account digits: number of digits , default is 6

Jump to

Keyboard shortcuts

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