security

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// V2 recaptcha api v2
	V2 VERSION = iota
	// V3 recaptcha api v3, more details can be found here : https://developers.google.com/recaptcha/docs/v3
	V3
	// DefaultThreshold Default minimin score when using V3 api
	DefaultThreshold float32 = 0.5
)

Variables

View Source
var (
	MaxErrors = 3
	ResetTime = time.Minute * 10
	WaitTime  = time.Minute * 10
)

Functions

This section is empty.

Types

type DBRedisInterface

type DBRedisInterface interface {
	Get(ctx context.Context, key string) *redis.StringCmd
}

type Error

type Error struct {

	// ErrorCodes contains any error codes from the recaptcha response.
	ErrorCodes []string
	// RequestError is true if the verify request to recaptcha failed.
	RequestError bool
	// contains filtered or unexported fields
}

Error custom error to pass ErrorCodes and RequestError to user.

func (*Error) Error

func (e *Error) Error() string

type LoginThrottle

type LoginThrottle struct {
	DBWriter *redis.Client
	DBReader *redis.Client
}

func NewLoginThrottle

func NewLoginThrottle(app bolo.App) *LoginThrottle

func (*LoginThrottle) BuildKey

func (l *LoginThrottle) BuildKey(ip, userID string) string

func (*LoginThrottle) CanLogin

func (l *LoginThrottle) CanLogin(userID string, c echo.Context) (bool, error)

func (*LoginThrottle) GetAccessRegistry

func (l *LoginThrottle) GetAccessRegistry(key string) *LoginThrottleStatus

func (*LoginThrottle) OnLoginFail

func (l *LoginThrottle) OnLoginFail(userID string, c echo.Context) error

func (*LoginThrottle) OnLoginSuccess

func (l *LoginThrottle) OnLoginSuccess(userID string, c echo.Context) error

func (*LoginThrottle) SetAccessRegistry

func (l *LoginThrottle) SetAccessRegistry(lts *LoginThrottleStatus) error

type LoginThrottleInterface

type LoginThrottleInterface interface {
	CanLogin(userID string, c echo.Context) (bool, error)
	OnLoginFail(userID string, c echo.Context) error
	OnLoginSuccess(userID string, c echo.Context) error
	BuildKey(ip, userID string) string
}

type LoginThrottleStatus

type LoginThrottleStatus struct {
	Key   string `json:"key"`
	Count int    `json:"count"`
	// unix timestamp
	WaitTime int64 `json:"wait_time"`
}

func (*LoginThrottleStatus) Can

func (lts *LoginThrottleStatus) Can() bool

func (*LoginThrottleStatus) OnError

func (lts *LoginThrottleStatus) OnError()

func (*LoginThrottleStatus) ToJSON

func (lts *LoginThrottleStatus) ToJSON() string

type ReCAPTCHA

type ReCAPTCHA struct {
	Secret        string
	ReCAPTCHALink string
	Version       VERSION
	Timeout       time.Duration
	// contains filtered or unexported fields
}

ReCAPTCHA recpatcha holder struct, make adding mocking code simpler.

func NewReCAPTCHA

func NewReCAPTCHA(ReCAPTCHASecret string, version VERSION, timeout time.Duration) (ReCAPTCHA, error)

NewReCAPTCHA new ReCAPTCHA instance if version is set to V2 uses recatpcha v2 API, get your secret from https://www.google.com/recaptcha/admin

if version is set to V2 uses recatpcha v2 API, get your secret from https://g.co/recaptcha/v3

func (*ReCAPTCHA) Verify

func (r *ReCAPTCHA) Verify(challengeResponse string) error

Verify returns `nil` if no error and the client solved the challenge correctly

func (*ReCAPTCHA) VerifyWithOptions

func (r *ReCAPTCHA) VerifyWithOptions(challengeResponse string, options VerifyOption) error

VerifyWithOptions returns `nil` if no error and the client solved the challenge correctly and all options are matching `Threshold` and `Action` are ignored when using V2 version

type VERSION

type VERSION int8

VERSION the recaptcha api version

type VerifyOption

type VerifyOption struct {
	Threshold      float32 // ignored in v2 recaptcha
	Action         string  // ignored in v2 recaptcha
	Hostname       string
	ApkPackageName string
	ResponseTime   time.Duration
	RemoteIP       string
}

VerifyOption verification options expected for the challenge

Jump to

Keyboard shortcuts

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