totp

package
v0.0.0-...-bf089be Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(opts GenerateOpts) (*otp.Key, error)

Generate 生成TOTP的密钥

func GenerateCode

func GenerateCode(secret string, t time.Time) (string, error)

GenerateCode 使用默认配置生成TOTP密码

func GenerateCodeCustom

func GenerateCodeCustom(secret string, t time.Time, opts Options) (passcode string, err error)

GenerateCodeCustom 使用自定义配置生成TOTP密码

func Validate

func Validate(passcode string, secret string) bool

Validate 使用默认配置验证TOTP密码

func ValidateCustom

func ValidateCustom(passcode string, secret string, t time.Time, opts Options) (bool, error)

ValidateCustom 使用自定义配置验证一个TOTP密码

Types

type GenerateOpts

type GenerateOpts struct {
	Issuer      string
	AccountName string
	Period      uint
	SecretSize  uint
	Digits      otp.Digits
	Algorithm   otp.Algorithm
}

GenerateOpts 为Generate()方法提供配置

type Options

type Options struct {
	// Period 表示TOTP的有效时间,单位为秒
	// 默认为30秒
	Period    uint
	Skew      uint
	Digits    otp.Digits
	Algorithm otp.Algorithm
}

Options 提供了TOTP的配置

Jump to

Keyboard shortcuts

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