Documentation ¶
Index ¶
- Constants
- func Code(secret string) string
- func CodeCustom(secret string, t time.Time) string
- func GenerateURLHOTP(opts KeyOpts) (url string)
- func GenerateURLTOTP(opts KeyOpts) (url string)
- func HOTPCode(secret string, counter uint64) (code string)
- func HOTPCodeCustom(secret string, counter uint64, opts *Opts) (code string)
- func KeyFromHOTPOpts(opts KeyOpts) (*xtp.Key, error)
- func KeyFromTOTPOpts(opts KeyOpts) (*xtp.Key, error)
- func KeyFromURL(url string) (*xtp.Key, error)
- func RandomSecret(length int) (secret string)
- func TOTPCode(secret string) (code string)
- func TOTPCodeCustom(secret string, t time.Time, opts *Opts) (code string)
- func VerifyHOTP(passcode string, counter uint64, secret string) bool
- func VerifyHOTPCustom(passcode string, counter uint64, secret string, opts *Opts) (ret bool)
- func VerifySecret(secret string) bool
- func VerifyTOTP(passcode string, secret string) bool
- func VerifyTOTPCustom(passcode string, secret string, t time.Time, opts *Opts) (ret bool)
- type KeyOpts
- type Opts
Constants ¶
const ( // AlgorithmSHA1 should be used for compatibility with Google Authenticator. // // See https://github.com/pquerna/otp/issues/55 for additional details. AlgorithmSHA1 = xtp.AlgorithmSHA1 AlgorithmSHA256 = xtp.AlgorithmSHA256 AlgorithmSHA512 = xtp.AlgorithmSHA512 AlgorithmMD5 = xtp.AlgorithmMD5 )
Variables ¶
This section is empty.
Functions ¶
func Code ¶
Code generates the totp code, with the default settings: digits=6, algorithm=SHA1, base now timestamp.
func CodeCustom ¶
CodeCustom generates the totp code, with the default settings: digits=6, algorithm=SHA1, with your specified timestamp.
func GenerateURLHOTP ¶
GenerateURLHOTP returns the HOTP URL as a string.
func GenerateURLTOTP ¶
GenerateURLTOTP returns the TOTP URL as a string.
func KeyFromHOTPOpts ¶
KeyFromHOTPOpts creates a new HOTP Key.
func KeyFromTOTPOpts ¶
KeyFromTOTPOpts creates a new TOTP Key.
func KeyFromURL ¶
KeyFromURL creates a new Key from an TOTP or HOTP url.
The URL format is documented here:
https://github.com/google/google-authenticator/wiki/Key-Uri-Format
func RandomSecret ¶
RandomSecret generates a random secret of given length (number of bytes) without padding, if rand.Read failed returns empty string.
func VerifyHOTPCustom ¶
func VerifySecret ¶
VerifySecret verifies the secret is valid, support padding or NoPadding format.
func VerifyTOTP ¶
Types ¶
type KeyOpts ¶
type KeyOpts 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 xtp.Digits // Algorithm to use for HMAC. Defaults to SHA1. Algorithm xtp.Algorithm // Reader to use for generating TOTP Key. Rand io.Reader // Counter for HOTP. if type is hotp: The counter parameter is required when provisioning a key for use with HOTP. It will set the initial counter value. Counter uint64 }
KeyOpts provides options for Generate(). The default values are compatible with Google-Authenticator.
Required: Issuer, AccountName, htop also need counter.
type Opts ¶
type Opts 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 xtp.Digits // Algorithm to use for HMAC. Defaults to SHA1. Algorithm xtp.Algorithm }
Opts provides options for ValidateCustom().
Only for TOTP: Period, Skew.