gauth

package module
v0.3.20210827132358 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: MIT Imports: 12 Imported by: 0

README

gauth

Google Authentication

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSecretLengthLss secret length less than 6
	ErrSecretLengthLss = errors.New("secret length lss 6 error")
	// ErrParam param error
	ErrParam = errors.New("param error")
)

Functions

func CreateSecret

func CreateSecret(length int) string

CreateSecret create secret

func GetCode

func GetCode(secret string) string

GetCode get code

func HmacSha1

func HmacSha1(key, data []byte) []byte

HmacSha1 hmac sha1

func VerifyCode

func VerifyCode(secret string, code string) bool

VerifyCode verify code

Types

type GAuth

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

GAuth struct of gauth

func NewGAuth

func NewGAuth() *GAuth

NewGAuth new gauth

func (*GAuth) CreateSecret

func (receiver *GAuth) CreateSecret(secretLen int) (string, error)

CreateSecret create new secret 16 characters, randomly chosen from the allowed base32 characters.

func (*GAuth) GetCode

func (receiver *GAuth) GetCode(secret string, timeSlices ...int64) (string, error)

GetCode Calculate the code, with given secret and point in time

func (*GAuth) SetCodeLength

func (receiver *GAuth) SetCodeLength(length float64) error

SetCodeLength Set the code length, should be >=6

func (*GAuth) VerifyCode

func (receiver *GAuth) VerifyCode(secret, code string) (bool, error)

VerifyCode Check if the code is correct. This will accept codes starting from $discrepancy*30sec ago to $discrepancy*30sec from now

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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