totp

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeQuery

func EncodeQuery(v url.Values) string

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.

Types

type Algorithm

type Algorithm int
const (
	SHA1 Algorithm = iota
	SHA256
	SHA512
	MD5
)

密码长度、密码有效期(时间间隔)、加密算法、密钥

func (Algorithm) GetAlgorithm

func (a Algorithm) GetAlgorithm() (h func() hash.Hash)

func (Algorithm) String

func (a Algorithm) String() string

type Key

type Key struct {
	// contains filtered or unexported fields
}

Key represents an TOTP or HTOP key.

func (*Key) Image

func (k *Key) Image(width int, height int) (image.Image, error)

type OpFunc

type OpFunc func(t *Totp)

func WithAlgorithm

func WithAlgorithm(algorithm Algorithm) OpFunc

func WithExpiration

func WithExpiration(expiration int) OpFunc

func WithSecret

func WithSecret(secret string) OpFunc

func WithSize

func WithSize(size int) OpFunc

type OtpUrl

type OtpUrl struct {
	Issuer  string // 公司或者组织的名字
	Account string // eg,email的地址
	// contains filtered or unexported fields
}

func NewOtpUrl

func NewOtpUrl(issuer string, account string, totp *Totp) *OtpUrl

func (*OtpUrl) GetUrl

func (o *OtpUrl) GetUrl() (*Key, error)

type Totp

type Totp struct {
	// contains filtered or unexported fields
}

func NewTotp

func NewTotp(ops ...OpFunc) *Totp

func (*Totp) GeneratePwd

func (t *Totp) GeneratePwd() (pwd string, err error)

GeneratePwd 生成密码

func (*Totp) ValidatePwd

func (t *Totp) ValidatePwd(pwd string) (bool, error)

Jump to

Keyboard shortcuts

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