opt

package module
v0.0.0-...-e745b09 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2021 License: MIT Imports: 11 Imported by: 0

README

go-opt

2fa,两因素验证

Documentation

Index

Constants

View Source
const (
	OtpTypeTotp = "totp"
	OtpTypeHotp = "hotp"
)

Variables

This section is empty.

Functions

func BuildUri

func BuildUri(otpType, secret, accountName, issuerName, algorithm string, initialCount, digits, period int) string

BuildUri https://github.com/google/google-authenticator/wiki/Key-Uri-Format

func GenerateSecret

func GenerateSecret() string

func Itob

func Itob(integer int) []byte

Types

type Auth

type Auth interface {
	//GenerateCode 生成验证码
	GenerateCode(input int) string
	//VerifyCode 验证验证码
	VerifyCode(input int, code string) bool
}

Auth 认证信息

type HOTP

type HOTP struct {
	OTP
}

https://tools.ietf.org/html/rfc4226 page 5

func NewDefaultHOTP

func NewDefaultHOTP() *HOTP

NewDefaultHotp digits default 6

func NewHOTP

func NewHOTP(secret string, digits int, hasher *Hasher) *HOTP

NewHotp create HOTP secret shared secret between client and server; each HOTP

generator has a different and unique secret K.

digits number of digits in an HOTP value hasher HMAC type

func (*HOTP) GenerateCode

func (h *HOTP) GenerateCode(count int) string

GenerateCode count 8-byte counter value, the moving factor. This counter

MUST be synchronized between the HOTP generator (client)
and the HOTP validator (server).

func (*HOTP) ProvisioningUri

func (h *HOTP) ProvisioningUri(accountName, issuerName string, initialCount int) string

ProvisioningUri create uri

func (*HOTP) VerifyCode

func (h *HOTP) VerifyCode(count int, value string) bool

VerifyCode count 8-byte counter value, the moving factor value code

type Hasher

type Hasher struct {
	HashName string
	Digest   func() hash.Hash
}

type OTP

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

https://github.com/ozgur-soft/otp/blob/master/src/otp.go

type TOTP

type TOTP struct {
	OTP
	// contains filtered or unexported fields
}

Totp https://github.com/xycxmz/go-totp https://tools.ietf.org/html/rfc6238

func NewDefaultTOTP

func NewDefaultTOTP() *TOTP

NewDefaultTOTP create digits 6 ,interval 30, TOTP

func NewTOTP

func NewTOTP(secret string, digits, interval int, hasher *Hasher) *TOTP

NewTOTP create TOTP secret shared secret digits number of digits interval a value that reflects a time hasher the crypto function to use

func (*TOTP) GenerateCode

func (t *TOTP) GenerateCode(timestamp int) string

GenerateCode timestamp Unix time rfc6238

func (*TOTP) NowWithExpiration

func (t *TOTP) NowWithExpiration() (string, int64)

NowWithExpiration return code and expirationTime

func (*TOTP) ProvisioningUri

func (t *TOTP) ProvisioningUri(accountName, issuerName string) string

ProvisioningUri create uri

func (*TOTP) VerifyCode

func (t *TOTP) VerifyCode(timestamp int, value string) bool

Jump to

Keyboard shortcuts

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