totp

package
v7.0.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2017 License: MIT, Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(opts GenerateOpts) (*otp.Key, error)

Generate a new TOTP Key.

func GenerateCode

func GenerateCode(secret string, t time.Time) (string, error)

GenerateCode creates a TOTP token using the current time. A shortcut for GenerateCodeCustom, GenerateCode uses a configuration that is compatible with Google-Authenticator and most clients.

func GenerateCodeCustom

func GenerateCodeCustom(secret string, t time.Time, opts ValidateOpts) (passcode string, err error)

GenerateCodeCustom takes a timepoint and produces a passcode using a secret and the provided opts. (Under the hood, this is making an adapted call to hotp.GenerateCodeCustom)

func Validate

func Validate(passcode string, secret string) bool

Validate a TOTP using the current time. A shortcut for ValidateCustom, Validate uses a configuration that is compatible with Google-Authenticator and most clients.

func ValidateCustom

func ValidateCustom(passcode string, secret string, t time.Time, opts ValidateOpts) (bool, error)

ValidateCustom validates a TOTP given a user specified time and custom options. Most users should use Validate() to provide an interpolatable TOTP experience.

Types

type GenerateOpts

type GenerateOpts struct {
	// Name of the issuing Organization/Company.
	Issuer string
	// Name of the User's Account (eg, email address)
	AccountName string
	// Number of seconds a TOTP hash is valid for. Defaults to 30 seconds.
	Period uint
	// Size in size of the generated Secret. Defaults to 10 bytes.
	SecretSize uint
	// Digits to request. Defaults to 6.
	Digits otp.Digits
	// Algorithm to use for HMAC. Defaults to SHA1.
	Algorithm otp.Algorithm
}

GenerateOpts provides options for Generate(). The default values are compatible with Google-Authenticator.

type ValidateOpts

type ValidateOpts struct {
	// Number of seconds a TOTP hash is valid for. Defaults to 30 seconds.
	Period uint
	// Periods before or after the current time to allow.  Value of 1 allows up to Period
	// of either side of the specified time.  Defaults to 0 allowed skews.  Values greater
	// than 1 are likely sketchy.
	Skew uint
	// Digits as part of the input. Defaults to 6.
	Digits otp.Digits
	// Algorithm to use for HMAC. Defaults to SHA1.
	Algorithm otp.Algorithm
}

ValidateOpts provides options for ValidateCustom().

Jump to

Keyboard shortcuts

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