verified

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: MIT Imports: 4 Imported by: 1

README

verified

verified 包括 captcha 和 reflux:

  • captcha: 用于图形验证器或问答验证器
  • reflux: 用于签发验证.

verified 有两种方式验证方式:

  • 一次性验证器(失败或成功立即失效)

    redis 存储格式: captcha: keyPrefix:{kind}:{id} -----> answer
    reflux: keyPrefix:{kind}:{key} -----> unique

  • 可多次验证(成功或失败超过最大错误限制次数则失效)

    redis 存储格式: captcha: keyPrefix:{kind}:{id} -----> { value -- answer, quota -- quota }
    reflux: keyPrefix:{kind}:{key} -----> { value -- unique, quota -- quota }
    value: 验证值
    quota: 最大错误限制次数

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Captcha

type Captcha[P CaptchaProvider, S Storage] struct {
	// contains filtered or unexported fields
}

Captcha verified captcha limit

func NewVerifiedCaptcha

func NewVerifiedCaptcha[P CaptchaProvider, S Storage](p P, store S, opts ...Option) *Captcha[P, S]

NewVerifiedCaptcha new captcha instance.

func (*Captcha[P, S]) Generate

func (v *Captcha[P, S]) Generate(ctx context.Context, kind string, opts ...GenerateOption) (id, question string, err error)

Generate generate id, question.

func (*Captcha[P, S]) Name

func (v *Captcha[P, S]) Name(kind string) string

Name the provider name

func (*Captcha[P, S]) Verify

func (v *Captcha[P, S]) Verify(ctx context.Context, kind, id, answer string) bool

Verify the answer.

type CaptchaDriver

type CaptchaDriver interface {
	Name() string
	GenerateQuestionAnswer() (*QuestionAnswer, error)
}

CaptchaDriver the captcha driver

type CaptchaProvider

type CaptchaProvider interface {
	AcquireDriver(kind string) CaptchaDriver
}

CaptchaProvider the captcha provider

type GenerateOption

type GenerateOption func(GenerateOptionSetter)

GenerateOption generate option

func WithGenerateKeyExpires

func WithGenerateKeyExpires(t time.Duration) GenerateOption

WithGenerateKeyExpires redis存验证码key的过期时间

func WithGenerateMaxErrQuota

func WithGenerateMaxErrQuota(quota int) GenerateOption

WithGenerateMaxErrQuota 设置最大错误验证次数 NOTE: 仅禁用一次性验证器时, 该功能有效

type GenerateOptionSetter

type GenerateOptionSetter interface {
	// contains filtered or unexported methods
}

GenerateOptionSetter generate option setter

type Option

type Option func(OptionSetter)

Option 选项

func WithKeyExpires

func WithKeyExpires(t time.Duration) Option

WithKeyExpires redis存验证码key的过期时间

func WithKeyPrefix

func WithKeyPrefix(k string) Option

WithKeyPrefix redis存验证码key的前缀, 默认 limit:captcha:

func WithMaxErrQuota

func WithMaxErrQuota(quota int) Option

SetMaxErrQuota 设置最大错误次数验证, 并禁用一次性验证 NOTE: 并设置最大错误次数验证, 将禁用一次性验证(默认验证器一次性有效)

type OptionSetter

type OptionSetter interface {
	// contains filtered or unexported methods
}

OptionSetter option setter

type QuestionAnswer

type QuestionAnswer struct {
	Id       string
	Question string
	Answer   string
}

QuestionAnswer question and answer for CaptchaDriver driver

type Reflux

type Reflux[P RefluxProvider, S Storage] struct {
	// contains filtered or unexported fields
}

Reflux verified reflux limiter

func NewVerifiedReflux

func NewVerifiedReflux[P RefluxProvider, S Storage](p P, s S, opts ...Option) *Reflux[P, S]

NewVerifiedReflux new reflux instance.

func (*Reflux[P, S]) Generate

func (v *Reflux[P, S]) Generate(ctx context.Context, kind, key string, opts ...GenerateOption) (string, error)

Generate generate uniqueId. use GenerateOption overwrite default key expires

func (*Reflux[P, S]) Name

func (v *Reflux[P, S]) Name() string

Name the provider name

func (*Reflux[P, S]) Verify

func (v *Reflux[P, S]) Verify(ctx context.Context, kind, key, answer string) bool

Verify the answer.

type RefluxProvider

type RefluxProvider interface {
	Name() string
	GenerateUniqueId() string
}

RefluxProvider the reflux provider

type Storage

type Storage interface {
	Store(context.Context, *StoreArgs) error
	Verify(context.Context, *VerifyArgs) bool
}

Storage store engine

type StoreArgs

type StoreArgs struct {
	DisableOneTime bool
	Key            string
	KeyExpires     time.Duration
	MaxErrQuota    int
	Answer         string
}

StoreArgs store arguments

type UnsupportedVerifiedCaptchaDriver

type UnsupportedVerifiedCaptchaDriver struct{}

func (UnsupportedVerifiedCaptchaDriver) GenerateQuestionAnswer

func (x UnsupportedVerifiedCaptchaDriver) GenerateQuestionAnswer() (*QuestionAnswer, error)

func (UnsupportedVerifiedCaptchaDriver) Name

type VerifyArgs

type VerifyArgs struct {
	DisableOneTime bool
	Key            string
	Answer         string
}

VerifyArgs verify arguments

Directories

Path Synopsis
v8
v9

Jump to

Keyboard shortcuts

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