### Get Hashing Algorithm as String Source: https://pkg.go.dev/github.com/pquerna/otp Returns the string representation of the Algorithm setting. ```go func (a Algorithm) String() string ``` -------------------------------- ### Get Digits as String Source: https://pkg.go.dev/github.com/pquerna/otp Returns the string representation of the Digits setting. ```go func (d Digits) String() string ``` -------------------------------- ### Get OTP Key as String Source: https://pkg.go.dev/github.com/pquerna/otp Returns the OTP URL as a string, suitable for sharing or embedding. ```go func (k *Key) String() string ``` -------------------------------- ### Get Number of OTP Digits Source: https://pkg.go.dev/github.com/pquerna/otp Returns the number of characters for the Digits setting. ```go func (d Digits) Length() int ``` -------------------------------- ### Get Hashing Function for Algorithm Source: https://pkg.go.dev/github.com/pquerna/otp Returns the hash.Hash implementation corresponding to the Algorithm. ```go func (a Algorithm) Hash() hash.Hash ``` -------------------------------- ### Get OTP Key Account Name Source: https://pkg.go.dev/github.com/pquerna/otp Retrieves the account name associated with the OTP key. ```go func (k *Key) AccountName() string ``` -------------------------------- ### Get OTP Key URL String Representation Source: https://pkg.go.dev/github.com/pquerna/otp Returns the OTP URL as a string. This is useful for generating QR codes or sharing the key configuration. ```go func (k *Key) URL() string ``` -------------------------------- ### Get OTP Key Type Source: https://pkg.go.dev/github.com/pquerna/otp Returns the type of the OTP key, either "hotp" or "totp". ```go func (k *Key) Type() string ``` -------------------------------- ### Get OTP Key Algorithm Source: https://pkg.go.dev/github.com/pquerna/otp Retrieves the hashing algorithm used by the OTP key. Defaults to SHA1 if not explicitly set. ```go func (k *Key) Algorithm() Algorithm ``` -------------------------------- ### Get OTP Key Encoder Source: https://pkg.go.dev/github.com/pquerna/otp Retrieves the encoder used for the OTP key. Defaults to "" (empty string) if not explicitly set. ```go func (k *Key) Encoder() Encoder ``` -------------------------------- ### Get OTP Key Period Source: https://pkg.go.dev/github.com/pquerna/otp Retrieves the rotation period in seconds for the OTP key. ```go func (k *Key) Period() uint64 ``` -------------------------------- ### Get OTP Key Secret Source: https://pkg.go.dev/github.com/pquerna/otp Retrieves the opaque secret for the OTP key. ```go func (k *Key) Secret() string ``` -------------------------------- ### Get OTP Key Digits Source: https://pkg.go.dev/github.com/pquerna/otp Retrieves the number of digits for the OTP passcode. Defaults to 6 if not explicitly set. ```go func (k *Key) Digits() Digits ``` -------------------------------- ### Get OTP Key Issuer Source: https://pkg.go.dev/github.com/pquerna/otp Retrieves the issuer name associated with the OTP key. ```go func (k *Key) Issuer() string ``` -------------------------------- ### Enroll a user with TOTP and QR code Source: https://pkg.go.dev/github.com/pquerna/otp Generates a new TOTP key, creates a QR code image for enrollment, and validates the initial passcode before storing the secret. ```go import ( "github.com/pquerna/otp/totp" "bytes" "image/png" ) key, err := totp.Generate(totp.GenerateOpts{ Issuer: "Example.com", AccountName: "alice@example.com", }) // Convert TOTP key into a QR code encoded as a PNG image. var buf bytes.Buffer img, err := key.Image(200, 200) png.Encode(&buf, img) // display the QR code to the user. display(buf.Bytes()) // Now Validate that the user's successfully added the passcode. passcode := promptForPasscode() valid := totp.Validate(passcode, key.Secret()) if valid { // User successfully used their TOTP, save it to your backend! storeSecret("alice@example.com", key.Secret()) } ``` -------------------------------- ### Generate HOTP Key Source: https://pkg.go.dev/github.com/pquerna/otp/hotp Creates a new HOTP Key. Use GenerateOpts to configure parameters like issuer, account name, secret size, and algorithm. ```go func Generate(opts GenerateOpts) (*otp.Key, error) ``` -------------------------------- ### Create Key from URL Source: https://pkg.go.dev/github.com/pquerna/otp Creates a new Key object from a given TOTP or HOTP URL. Ensure the URL format adheres to the Google Authenticator Key URI Format. ```go func NewKeyFromURL(orig string) (*Key, error) ``` -------------------------------- ### GenerateOpts Struct Source: https://pkg.go.dev/github.com/pquerna/otp/hotp Defines options for generating HOTP keys. Configure issuer, account name, secret size, digits, algorithm, and the random number reader. ```go type GenerateOpts struct { // Name of the issuing Organization/Company. Issuer string // Name of the User's Account (eg, email address) AccountName string // Size in size of the generated Secret. Defaults to 10 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 HOTP Key. Rand io.Reader } ``` -------------------------------- ### Generate Options Structure Source: https://pkg.go.dev/github.com/pquerna/otp/totp Configuration options for the Generate function. ```go 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 } ``` -------------------------------- ### Key Generation and Management Source: https://pkg.go.dev/github.com/pquerna/otp This section covers the creation and manipulation of OTP keys, including generating keys from URLs and accessing key properties. ```APIDOC ## func NewKeyFromURL(orig string) (*Key, error) ### Description Creates a new Key from an TOTP or HOTP url. ### Method `NewKeyFromURL` ### Endpoint N/A (Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **Key** (*Key) - A pointer to the created Key object. - **error** (error) - An error if the URL parsing fails. #### Response Example None ``` ```APIDOC ## func (*Key) AccountName() string ### Description AccountName returns the name of the user's account. ### Method `AccountName` ### Endpoint N/A (Method on Key) ### Parameters None ### Request Example None ### Response #### Success Response (200) - **string** - The account name. #### Response Example None ``` ```APIDOC ## func (*Key) Algorithm() Algorithm ### Description Algorithm returns the algorithm used or the default (SHA1). ### Method `Algorithm` ### Endpoint N/A (Method on Key) ### Parameters None ### Request Example None ### Response #### Success Response (200) - **Algorithm** (Algorithm) - The hashing algorithm used. #### Response Example None ``` ```APIDOC ## func (*Key) Digits() Digits ### Description Digits returns a tiny int representing the number of OTP digits. ### Method `Digits` ### Endpoint N/A (Method on Key) ### Parameters None ### Request Example None ### Response #### Success Response (200) - **Digits** (Digits) - The number of digits. #### Response Example None ``` ```APIDOC ## func (*Key) Encoder() Encoder ### Description Encoder returns the encoder used or the default ("steam"). ### Method `Encoder` ### Endpoint N/A (Method on Key) ### Parameters None ### Request Example None ### Response #### Success Response (200) - **Encoder** (Encoder) - The encoder type. #### Response Example None ``` ```APIDOC ## func (*Key) Image(width int, height int) (image.Image, error) ### Description 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. ### Method `Image` ### Endpoint N/A (Method on Key) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters #### Path Parameters - **width** (int) - Required - The desired width of the image. - **height** (int) - Required - The desired height of the image. ### Request Example None ### Response #### Success Response (200) - **image.Image** (image.Image) - The generated QR-code image. - **error** (error) - An error if image generation fails. #### Response Example None ``` ```APIDOC ## func (*Key) Issuer() string ### Description Issuer returns the name of the issuing organization. ### Method `Issuer` ### Endpoint N/A (Method on Key) ### Parameters None ### Request Example None ### Response #### Success Response (200) - **string** - The issuer name. #### Response Example None ``` ```APIDOC ## func (*Key) Period() uint64 ### Description Period returns a tiny int representing the rotation time in seconds. ### Method `Period` ### Endpoint N/A (Method on Key) ### Parameters None ### Request Example None ### Response #### Success Response (200) - **uint64** - The period in seconds. #### Response Example None ``` ```APIDOC ## func (*Key) Secret() string ### Description Secret returns the opaque secret for this Key. ### Method `Secret` ### Endpoint N/A (Method on Key) ### Parameters None ### Request Example None ### Response #### Success Response (200) - **string** - The secret key. #### Response Example None ``` ```APIDOC ## func (*Key) String() string ### Description String returns the OTP URL as a string. ### Method `String` ### Endpoint N/A (Method on Key) ### Parameters None ### Request Example None ### Response #### Success Response (200) - **string** - The OTP URL. #### Response Example None ``` ```APIDOC ## func (*Key) Type() string ### Description Type returns "hotp" or "totp". ### Method `Type` ### Endpoint N/A (Method on Key) ### Parameters None ### Request Example None ### Response #### Success Response (200) - **string** - The type of OTP ("hotp" or "totp"). #### Response Example None ``` ```APIDOC ## func (*Key) URL() string ### Description URL returns the OTP URL as a string. ### Method `URL` ### Endpoint N/A (Method on Key) ### Parameters None ### Request Example None ### Response #### Success Response (200) - **string** - The OTP URL. #### Response Example None ``` -------------------------------- ### Validate Options Structure Source: https://pkg.go.dev/github.com/pquerna/otp/totp Configuration options for the ValidateCustom function. ```go 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 // Encoder to use for output code. Encoder otp.Encoder } ``` -------------------------------- ### Generate HOTP Code (Google Authenticator Compatible) Source: https://pkg.go.dev/github.com/pquerna/otp/hotp Generates an HOTP passcode using a secret and counter. This is a convenient shortcut for GenerateCodeCustom, compatible with Google Authenticator. ```go func GenerateCode(secret string, counter uint64) (string, error) ``` -------------------------------- ### Define OTP Encoders Source: https://pkg.go.dev/github.com/pquerna/otp Defines the encoders used for OTP keys. EncoderDefault represents the standard encoding, while EncoderSteam is specific to Steam Guard. ```go const ( EncoderDefault Encoder = "" EncoderSteam Encoder = "steam" ) ``` -------------------------------- ### Generate QR Code Image for OTP Key Source: https://pkg.go.dev/github.com/pquerna/otp Generates a QR code image for an OTP key with the specified width and height. This image can be used by authenticator apps to enroll the key. ```go func (k *Key) Image(width int, height int) (image.Image, error) ``` -------------------------------- ### Define OTP Hashing Algorithms Source: https://pkg.go.dev/github.com/pquerna/otp Defines the hashing algorithms that can be used in the HMAC operation for OTPs. AlgorithmSHA1 is recommended for compatibility with Google Authenticator. ```go 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 ) ``` -------------------------------- ### ValidateOpts Struct Source: https://pkg.go.dev/github.com/pquerna/otp/hotp Provides options for customizing HOTP validation. Specify digits, algorithm, and the encoder to use for validation. ```go type ValidateOpts struct { // Digits as part of the input. Defaults to 6. Digits otp.Digits // Algorithm to use for HMAC. Defaults to SHA1. Algorithm otp.Algorithm // Encoder to use for output code. Encoder otp.Encoder } ``` -------------------------------- ### Define Missing Account Name Error Source: https://pkg.go.dev/github.com/pquerna/otp This variable defines the error returned when the AccountName is not set during key generation. ```go var ErrGenerateMissingAccountName = errors.New("AccountName must be set") ``` -------------------------------- ### HOTP Generation and Validation Functions Source: https://pkg.go.dev/github.com/pquerna/otp/hotp Core functions for generating HOTP keys, creating passcodes, and validating them. ```APIDOC ## Generate ### Description Creates a new HOTP Key based on provided options. ### Parameters - **opts** (GenerateOpts) - Required - Configuration options for the key generation. ### Response - **key** (*otp.Key) - The generated HOTP key. - **err** (error) - Error object if generation fails. ## GenerateCode ### Description Creates an HOTP passcode given a counter and secret, compatible with Google-Authenticator. ### Parameters - **secret** (string) - Required - The secret key. - **counter** (uint64) - Required - The counter value. ### Response - **passcode** (string) - The generated passcode. - **err** (error) - Error object if generation fails. ## Validate ### Description Validates an HOTP passcode given a counter and secret, compatible with Google-Authenticator. ### Parameters - **passcode** (string) - Required - The passcode to validate. - **counter** (uint64) - Required - The counter value. - **secret** (string) - Required - The secret key. ### Response - **valid** (bool) - Returns true if the passcode is valid. ``` -------------------------------- ### Format OTP Digits Source: https://pkg.go.dev/github.com/pquerna/otp Formats an integer into a zero-filled string according to the Digits setting. ```go func (d Digits) Format(in int32) string ``` -------------------------------- ### Generate HOTP Code with Custom Options Source: https://pkg.go.dev/github.com/pquerna/otp/hotp Generates an HOTP passcode using a secret, counter, and custom validation options. This allows for fine-grained control over the passcode generation process. ```go func GenerateCodeCustom(secret string, counter uint64, opts ValidateOpts) (passcode string, err error) ``` -------------------------------- ### Define Missing Issuer Error Source: https://pkg.go.dev/github.com/pquerna/otp This variable defines the error returned when the Issuer is not set during key generation. ```go var ErrGenerateMissingIssuer = errors.New("Issuer must be set") ``` -------------------------------- ### Validate HOTP Code (Google Authenticator Compatible) Source: https://pkg.go.dev/github.com/pquerna/otp/hotp Validates an HOTP passcode against a counter and secret. This is a shortcut for ValidateCustom and is compatible with Google Authenticator. ```go func Validate(passcode string, counter uint64, secret string) bool ``` -------------------------------- ### EncodeQuery function signature Source: https://pkg.go.dev/github.com/pquerna/otp/internal Use this function to encode URL values where spaces must be represented as %20 for compatibility with specific authenticator apps. ```go func EncodeQuery(v url.Values) string ``` -------------------------------- ### Generate TOTP Code Source: https://pkg.go.dev/github.com/pquerna/otp/totp Creates a TOTP token using the current time, compatible with Google-Authenticator. ```go func GenerateCode(secret string, t time.Time) (string, error) ``` -------------------------------- ### Validate HOTP Code with Custom Options Source: https://pkg.go.dev/github.com/pquerna/otp/hotp Validates an HOTP passcode with customizable options. Most users should prefer the simpler Validate() function unless specific configurations are needed. ```go func ValidateCustom(passcode string, counter uint64, secret string, opts ValidateOpts) (bool, error) ``` -------------------------------- ### Algorithm Type Source: https://pkg.go.dev/github.com/pquerna/otp Details about the Algorithm type, used to specify the hashing function for OTPs. ```APIDOC ## type Algorithm int ### Description Algorithm represents the hashing function to use in the HMAC operation needed for OTPs. ### Constants - **AlgorithmSHA1** (Algorithm): Should be used for compatibility with Google Authenticator. - **AlgorithmSHA256** (Algorithm): SHA256 hashing algorithm. - **AlgorithmSHA512** (Algorithm): SHA512 hashing algorithm. - **AlgorithmMD5** (Algorithm): MD5 hashing algorithm. ### Methods #### func (a Algorithm) Hash() hash.Hash ### Description Hash returns the standard library hash.Hash for the algorithm. ### Method `Hash` ### Endpoint N/A (Method on Algorithm) ### Parameters None ### Request Example None ### Response #### Success Response (200) - **hash.Hash** - The hash.Hash implementation for the algorithm. #### Response Example None ``` ```APIDOC ## func (a Algorithm) String() string ### Description String returns the string representation of the Algorithm. ### Method `String` ### Endpoint N/A (Method on Algorithm) ### Parameters None ### Request Example None ### Response #### Success Response (200) - **string** - The string representation of the algorithm (e.g., "SHA1", "SHA256"). #### Response Example None ``` -------------------------------- ### func EncodeQuery Source: https://pkg.go.dev/github.com/pquerna/otp/internal Encodes URL values using %20 for spaces instead of the standard + character, ensuring compatibility with specific authenticator apps. ```APIDOC ## func EncodeQuery ### Description EncodeQuery is a copy-paste of url.Values.Encode, except it uses %20 instead of + to encode spaces. This is necessary to correctly render spaces in some authenticator apps, like Google Authenticator. ### Signature `func EncodeQuery(v url.Values) string` ### Parameters - **v** (url.Values) - Required - The set of URL query parameters to encode. ``` -------------------------------- ### TOTP Configuration Types Source: https://pkg.go.dev/github.com/pquerna/otp/totp Types used for configuring TOTP generation and validation. ```APIDOC ## Type: GenerateOpts ### Description GenerateOpts provides options for Generate(). The default values are compatible with Google-Authenticator. ### Fields - **Issuer** (string) - Name of the issuing Organization/Company. - **AccountName** (string) - Name of the User's Account (eg, email address). - **Period** (uint) - Number of seconds a TOTP hash is valid for. Defaults to 30 seconds. - **SecretSize** (uint) - Size in bytes of the generated Secret. Defaults to 20 bytes. - **Secret** ([]byte) - Secret to store. Defaults to a randomly generated secret of SecretSize. You should generally leave this empty. - **Digits** (otp.Digits) - Digits to request. Defaults to 6. - **Algorithm** (otp.Algorithm) - Algorithm to use for HMAC. Defaults to SHA1. - **Rand** (io.Reader) - Reader to use for generating TOTP Key. ## Type: ValidateOpts ### Description ValidateOpts provides options for ValidateCustom(). ### Fields - **Period** (uint) - Number of seconds a TOTP hash is valid for. Defaults to 30 seconds. - **Skew** (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. - **Digits** (otp.Digits) - Digits as part of the input. Defaults to 6. - **Algorithm** (otp.Algorithm) - Algorithm to use for HMAC. Defaults to SHA1. - **Encoder** (otp.Encoder) - Encoder to use for output code. ``` -------------------------------- ### Generate Custom TOTP Code Source: https://pkg.go.dev/github.com/pquerna/otp/totp Produces a passcode using a secret, a specific timepoint, and custom validation options. ```go func GenerateCodeCustom(secret string, t time.Time, opts ValidateOpts) (passcode string, err error) ``` -------------------------------- ### Error Variables Source: https://pkg.go.dev/github.com/pquerna/otp Common error variables used within the OTP package. ```APIDOC ## Variables ### ErrGenerateMissingAccountName - **Type**: `error` - **Description**: Returned when the AccountName must be set but is missing during key generation. ### ErrGenerateMissingIssuer - **Type**: `error` - **Description**: Returned when the Issuer must be set but is missing during key generation. ### ErrValidateInputInvalidLength - **Type**: `error` - **Description**: Returned when the provided passcode length is unexpected during validation. ### ErrValidateSecretInvalidBase32 - **Type**: `error` - **Description**: Returned when decoding the secret as base32 fails. ``` -------------------------------- ### TOTP Generation API Source: https://pkg.go.dev/github.com/pquerna/otp/totp Functions for generating TOTP keys and codes. ```APIDOC ## Generate ### Description Generate a new TOTP Key. ### Method func ### Endpoint N/A ### Parameters #### Request Body - **opts** (GenerateOpts) - Required - Options for generating the key. ### Response #### Success Response (200) - ***otp.Key** - The generated TOTP key. - **error** - An error if generation fails. ## GenerateCode ### Description 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. ### Method func ### Endpoint N/A ### Parameters #### Request Body - **secret** (string) - Required - The secret key. - **t** (time.Time) - Required - The current time. ### Response #### Success Response (200) - **string** - The generated TOTP code. - **error** - An error if generation fails. ## GenerateCodeCustom ### Description 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) ### Method func ### Endpoint N/A ### Parameters #### Request Body - **secret** (string) - Required - The secret key. - **t** (time.Time) - Required - The current time. - **opts** (ValidateOpts) - Required - Options for generating the code. ### Response #### Success Response (200) - **passcode** (string) - The generated TOTP passcode. - **err** (error) - An error if generation fails. ``` -------------------------------- ### Encoder Type Source: https://pkg.go.dev/github.com/pquerna/otp Details about the Encoder type, used to specify encoding for OTPs. ```APIDOC ## type Encoder string ### Description Encoder represents the encoding type used for OTPs. ### Constants - **EncoderDefault** (Encoder): The default encoder. - **EncoderSteam** (Encoder): The Steam encoder. ### Methods None explicitly documented for direct use as API endpoints. ``` -------------------------------- ### Define OTP Passcode Digits Source: https://pkg.go.dev/github.com/pquerna/otp Defines the number of digits in an OTP passcode. DigitsSix and DigitsEight are the most common values. ```go const ( DigitsSix Digits = 6 DigitsEight Digits = 8 ) ``` -------------------------------- ### Validate TOTP Code Source: https://pkg.go.dev/github.com/pquerna/otp/totp Validates a TOTP passcode using the current time and standard configuration. ```go func Validate(passcode string, secret string) bool ``` -------------------------------- ### Define Invalid Length Error Source: https://pkg.go.dev/github.com/pquerna/otp This variable defines the error returned when the provided passcode length is unexpected. ```go var ErrValidateInputInvalidLength = errors.New("Input length unexpected") ``` -------------------------------- ### Define Invalid Base32 Secret Error Source: https://pkg.go.dev/github.com/pquerna/otp This variable defines the error returned when decoding the secret as base32 fails. ```go var ErrValidateSecretInvalidBase32 = errors.New("Decoding of secret as base32 failed.") ``` -------------------------------- ### Validate Custom TOTP Code Source: https://pkg.go.dev/github.com/pquerna/otp/totp Validates a TOTP passcode using a user-specified time and custom options. ```go func ValidateCustom(passcode string, secret string, t time.Time, opts ValidateOpts) (bool, error) ``` -------------------------------- ### Validate a TOTP passcode Source: https://pkg.go.dev/github.com/pquerna/otp Validates a user-provided passcode against a previously stored secret. ```go import "github.com/pquerna/otp/totp" passcode := promptForPasscode() secret := getSecret("alice@example.com") valid := totp.Validate(passcode, secret) if valid { // Success! continue login process. } ``` -------------------------------- ### Digits Type Source: https://pkg.go.dev/github.com/pquerna/otp Details about the Digits type, used to specify the number of digits in an OTP passcode. ```APIDOC ## type Digits int ### Description Digits represents the number of digits present in the user's OTP passcode. Six and Eight are the most common values. ### Constants - **DigitsSix** (Digits): Represents 6 digits. - **DigitsEight** (Digits): Represents 8 digits. ### Methods #### func (d Digits) Format(in int32) string ### Description Format converts an integer into the zero-filled size for this Digits. ### Method `Format` ### Endpoint N/A (Method on Digits) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters #### Path Parameters - **in** (int32) - Required - The integer to format. ### Request Example None ### Response #### Success Response (200) - **string** - The zero-filled string representation of the number. #### Response Example None ``` ```APIDOC ## func (d Digits) Length() int ### Description Length returns the number of characters for this Digits. ### Method `Length` ### Endpoint N/A (Method on Digits) ### Parameters None ### Request Example None ### Response #### Success Response (200) - **int** - The number of digits. #### Response Example None ``` ```APIDOC ## func (d Digits) String() string ### Description String returns the string representation of the Digits. ### Method `String` ### Endpoint N/A (Method on Digits) ### Parameters None ### Request Example None ### Response #### Success Response (200) - **string** - The string representation of the number of digits (e.g., "6", "8"). #### Response Example None ``` -------------------------------- ### TOTP Validation API Source: https://pkg.go.dev/github.com/pquerna/otp/totp Functions for validating TOTP codes. ```APIDOC ## Validate ### Description Validate a TOTP using the current time. A shortcut for ValidateCustom, Validate uses a configuration that is compatible with Google-Authenticator and most clients. ### Method func ### Endpoint N/A ### Parameters #### Request Body - **passcode** (string) - Required - The TOTP code to validate. - **secret** (string) - Required - The secret key. ### Response #### Success Response (200) - **bool** - True if the passcode is valid, false otherwise. ## ValidateCustom ### Description ValidateCustom validates a TOTP given a user specified time and custom options. Most users should use Validate() to provide an interpolatable TOTP experience. ### Method func ### Endpoint N/A ### Parameters #### Request Body - **passcode** (string) - Required - The TOTP code to validate. - **secret** (string) - Required - The secret key. - **t** (time.Time) - Required - The current time. - **opts** (ValidateOpts) - Required - Options for validation. ### Response #### Success Response (200) - **bool** - True if the passcode is valid, false otherwise. - **error** - An error if validation fails. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.