Documentation ¶
Index ¶
- func Generate(opts GenerateOpts) (*otp.Key, error)
- func GenerateCode(secret string, t time.Time) (string, error)
- func GenerateCodeCustom(secret string, t time.Time, opts ValidateOpts) (passcode string, err error)
- func Validate(passcode string, secret string) bool
- func ValidateCustom(passcode string, secret string, t time.Time, opts ValidateOpts) (bool, error)
- type GenerateOpts
- type ValidateOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateCode ¶
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 ¶
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 ¶
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 ¶
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 20 bytes. SecretSize uint // Secret to store. Defaults to a randomly generated secret of SecretSize. You should generally leave this empty. Secret []byte // Digits to request. Defaults to 6. Digits otp.Digits // Algorithm to use for HMAC. Defaults to SHA1. Algorithm otp.Algorithm // Reader to use for generating TOTP Key. Rand io.Reader }
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().