totp

package
v0.0.0-...-604e745 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Interval for totp tokens
	Interval = 30
	// PinModulo pin mod value
	PinModulo = 1000000
	// DefaultBase32String base 32 characters
	DefaultBase32String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
)

Variables

View Source
var (
	// ZerosOnRightModLookup lookup table for calculating number of trailing zeroes
	// Integer.numberOfTrailingZeros
	// http://stackoverflow.com/questions/5471129/number-of-trailing-zeros
	// http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightModLookup
	ZerosOnRightModLookup = []int{
		32, 0, 1, 26, 2, 23, 27, 0, 3, 16, 24, 30, 28, 11, 0, 13, 4, 7, 17,
		0, 25, 22, 31, 15, 29, 10, 12, 6, 0, 21, 14, 9, 5, 20, 8, 19, 18,
	}
)

Functions

func GenerateResponseCode

func GenerateResponseCode(secret string, challenge int64, codeLength int) (string, error)

GenerateResponseCode 生成密码

func GetChallenge

func GetChallenge() int64

GetChallenge value

func GetTotpCode

func GetTotpCode(secret string, codeLength int) []string

GetTotpCode 获取totpcode, 这里会生成3个code,当前时间,前30s,后30s 为了预防客户端跟服务端的时间差太大

func NewTotpToken

func NewTotpToken(length int) string

NewTotpToken 新生成token

func ValidTotpCode

func ValidTotpCode(totpToken, totpCode string) bool

ValidTotpCode 验证totp code

Types

type Base32Decode

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

Base32Decode struct

func DefaultNewBase32Decode

func DefaultNewBase32Decode() *Base32Decode

DefaultNewBase32Decode decoder

func NewBase32Decode

func NewBase32Decode(encode string) *Base32Decode

NewBase32Decode 新建base32解码器

func (*Base32Decode) Decode

func (dec *Base32Decode) Decode(encoded string) ([]byte, error)

Decode Base 32 Decode of encoded string

Jump to

Keyboard shortcuts

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