twofa

package
v1.0.602 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCode = errors.New("invalid code")

Functions

func ComputeCode

func ComputeCode(secret string, value int64) int

Types

type OTPConfig

type OTPConfig struct {
	Secret        string // 80-bit base32 encoded string of the user's secret
	WindowSize    int    // valid range: technically 0..100 or so, but beyond 3-5 is probably bad security
	HotpCounter   int    // the current otp counter.  0 if the user uses time-based codes instead.
	DisallowReuse []int  // timestamps in the current window unavailable for re-use
	ScratchCodes  []int  // an array of 8-digit numeric codes that can be used to log in
	UTC           bool   // use UTC for the timestamp instead of local time
}

func (*OTPConfig) Authenticate

func (c *OTPConfig) Authenticate(password string) (bool, error)

Authenticate a one-time-password against the given OTPConfig Returns true/false if the authentication was successful. Returns error if the password is incorrectly formatted (not a zero-padded 6 or non-zero-padded 8 digit number).

func (*OTPConfig) ProvisionURI

func (c *OTPConfig) ProvisionURI(user string) string

ProvisionURI generates a URI that can be turned into a QR code to configure a Google Authenticator mobile app.

func (*OTPConfig) ProvisionURIWithIssuer

func (c *OTPConfig) ProvisionURIWithIssuer(user string, issuer string) string

ProvisionURIWithIssuer generates a URI that can be turned into a QR code to configure a Google Authenticator mobile app. It respects the recommendations on how to avoid conflicting accounts.

See https://github.com/google/google-authenticator/wiki/Conflicting-Accounts

type TwoFa

type TwoFa struct {
}

func New

func New() *TwoFa

func (*TwoFa) GenerateSecret

func (c *TwoFa) GenerateSecret() string

func (*TwoFa) New

func (c *TwoFa) New(account, issuer string) (secret string, image []byte, err error)

func (*TwoFa) NewOTP

func (c *TwoFa) NewOTP(secret string, utc bool) *OTPConfig

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL