OOB OTP Secret Code Generator (secretcode/oob_otp.go)

authgear-server · pkg/util/secretcode/oob_otp.go · go · Apache-2.0
auth, security, lang:go, tag:crypto

Generates, compares, and validates out-of-band one-time password (OOB OTP) secret codes securely. Reuse in authentication and multi-factor authorization flows.

// Source: https://github.com/authgear/authgear-server | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
package secretcode

import (
	"context"
	"crypto/subtle"
	"fmt"
	"strings"

	"github.com/authgear/authgear-server/pkg/util/rand"
)

const oobOTPLength = 6

var OOBOTPSecretCode = OOBOTPSecretCodeType{}

type OOBOTPSecretCodeType struct{}

func (OOBOTPSecretCodeType) Length() int {
	return oobOTPLength
}

func (OOBOTPSecretCodeType) Generate() string {
	code := rand.StringWithAlphabet(oobOTPLength, "0123456789", rand.SecureRand)
	return code
}

func (OOBOTPSecretCodeType) GenerateFixed(fixedCode string) string {
	return fixedCode
}

func (OOBOTPSecretCodeType) Compare(a, b string)

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key