When generating a Key, the Account Name must be set.
var ErrGenerateMissingAccountName = errors.New("AccountName must be set")
When generating a Key, the Issuer must be set.
var ErrGenerateMissingIssuer = errors.New("Issuer must be set")
The user provided passcode length was not expected.
var ErrValidateInputInvalidLength = errors.New("Input length unexpected")
Error when attempting to convert the secret from base32 to raw bytes.
var ErrValidateSecretInvalidBase32 = errors.New("Decoding of secret as base32 failed.")
Algorithm represents the hashing function to use in the HMAC operation needed for OTPs.
type Algorithm int
const ( // AlgorithmSHA1 should be used for compatibility with Google Authenticator. // // See https://github.com/pquerna/otp/issues/55 for additional details. AlgorithmSHA1 Algorithm = iota AlgorithmSHA256 AlgorithmSHA512 AlgorithmMD5 )
func (a Algorithm) Hash() hash.Hash
func (a Algorithm) String() string
Digits represents the number of digits present in the user's OTP passcode. Six and Eight are the most common values.
type Digits int
const ( DigitsSix Digits = 6 DigitsEight Digits = 8 )
func (d Digits) Format(in int32) string
Format converts an integer into the zero-filled size for this Digits.
func (d Digits) Length() int
Length returns the number of characters for this Digits.
func (d Digits) String() string
Key represents an TOTP or HTOP key.
type Key struct {
// contains filtered or unexported fields
}
func NewKeyFromURL(orig string) (*Key, error)
NewKeyFromURL 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 (k *Key) AccountName() string
AccountName returns the name of the user's account.
func (k *Key) Image(width int, height int) (image.Image, error)
Image returns an QR-Code image of the specified width and height, suitable for use by many clients like Google-Authenricator to enroll a user's TOTP/HOTP key.
func (k *Key) Issuer() string
Issuer returns the name of the issuing organization.
func (k *Key) Period() uint64
Period returns a tiny int representing the rotation time in seconds.
func (k *Key) Secret() string
Secret returns the opaque secret for this Key.
func (k *Key) String() string
func (k *Key) Type() string
Type returns "hotp" or "totp".
func (k *Key) URL() string
URL returns the OTP URL as a string