otp

package
v0.0.0-...-5a547ea Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2018 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

View Source
const (
	TypeTOTP string = "totp"
	TypeHOTP        = "hotp"
)

Variables

View Source
var (
	ErrNil      error = errors.New("otp: Has not been initialized")
	ErrID             = errors.New("otp: Error id")
	ErrType           = errors.New("otp: Error type")
	ErrExist          = errors.New("otp: Exist id")
	ErrNotExist       = errors.New("otp: Not exist id")
	ErrNotOpen        = errors.New("otp: Close this auth")
)

Functions

func GenerateSecret

func GenerateSecret(lens ...int) string

func ValidSecret

func ValidSecret(secret string, lens ...int) bool

func ValidType

func ValidType(t string) bool

Types

type Authenticator

type Authenticator struct {
	Type         string
	SecretLength int

	OTPAuth map[string]OTP

	OTPOpen map[string]bool

	OTPActive map[string]bool
	// contains filtered or unexported fields
}

func NewAuthenticator

func NewAuthenticator(_type string, secretLength int) (*Authenticator, error)

func (*Authenticator) Active

func (a *Authenticator) Active(id string)

func (*Authenticator) AddSecret

func (a *Authenticator) AddSecret(id, secret string, update bool) (OTP, error)

func (*Authenticator) Close

func (a *Authenticator) Close(id string)

func (*Authenticator) GetSecret

func (a *Authenticator) GetSecret(id string) string

func (*Authenticator) Inactive

func (a *Authenticator) Inactive(id string)

func (*Authenticator) IsActive

func (a *Authenticator) IsActive(id string) bool

func (*Authenticator) IsOpen

func (a *Authenticator) IsOpen(id string) bool

func (*Authenticator) Open

func (a *Authenticator) Open(id string)

func (*Authenticator) URL

func (a *Authenticator) URL(id, user, issuer string) string

func (*Authenticator) ValidSecret

func (a *Authenticator) ValidSecret(id string) bool

func (*Authenticator) Verify

func (a *Authenticator) Verify(id, password string) (bool, error)

type HOTP

type HOTP struct {
	OTP          googleauth.OTPConfig
	SecretLength int
}

func NewHOTP

func NewHOTP(windowSize, secretLength int) *HOTP

func (*HOTP) GetSecret

func (t *HOTP) GetSecret() string

func (*HOTP) SetSecret

func (t *HOTP) SetSecret(secret string) OTP

func (*HOTP) URL

func (t *HOTP) URL(user, issuer string) string

func (*HOTP) ValidSecret

func (t *HOTP) ValidSecret() bool

func (*HOTP) Verify

func (t *HOTP) Verify(password string) (bool, error)

type OTP

type OTP interface {
	SetSecret(secret string) OTP
	GetSecret() string
	ValidSecret() bool
	URL(user, issuer string) string
	Verify(password string) (bool, error)
}

type TOTP

type TOTP struct {
	OTP          googleauth.OTPConfig
	SecretLength int
}

func NewTOTP

func NewTOTP(windowSize, secretLength int) *TOTP

func (*TOTP) GetSecret

func (t *TOTP) GetSecret() string

func (*TOTP) SetSecret

func (t *TOTP) SetSecret(secret string) OTP

func (*TOTP) URL

func (t *TOTP) URL(user, issuer string) string

func (*TOTP) ValidSecret

func (t *TOTP) ValidSecret() bool

func (*TOTP) Verify

func (t *TOTP) Verify(password string) (bool, error)

Jump to

Keyboard shortcuts

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