Documentation
¶
Index ¶
- func CopyStructByJson(src, dst interface{})
- func CopyStructToMap(src interface{}) map[string]interface{}
- func EncryptPassword(password string) (string, error)
- func InArray(k string, arr []string) bool
- func Keys[K comparable, V any](m map[K]V) []K
- func Md5(str string) string
- func RandomString(n int) string
- func SafeGo(f interface{}, params ...interface{})
- func StringConcat(strs ...string) string
- func Values[K comparable, V any](m map[K]V) []V
- func VerifyPassword(hash, input string) (bool, string, error)
- type B64MathCaptchaProvider
- type B64StringCaptchaProvider
- type BanRecord
- type CaptchaMeta
- type CaptchaProvider
- type LoginLimiter
- func (ll *LoginLimiter) CheckSecurityStatus(ip string) (banned bool, captchaRequired bool)
- func (ll *LoginLimiter) DrawCaptcha(content string) (err error, str string)
- func (ll *LoginLimiter) RecordFailedAttempt(ip string)
- func (ll *LoginLimiter) RegisterProvider(p CaptchaProvider)
- func (ll *LoginLimiter) RemoveAttempts(ip string)
- func (ll *LoginLimiter) RequireCaptcha() (error, CaptchaMeta)
- func (ll *LoginLimiter) VerifyCaptcha(id, answer string) bool
- type SecurityPolicy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyStructByJson ¶
func CopyStructByJson(src, dst interface{})
func CopyStructToMap ¶
func CopyStructToMap(src interface{}) map[string]interface{}
CopyStructToMap 结构体转map
func EncryptPassword ¶ added in v2.6.24
EncryptPassword hashes the input password using bcrypt. An error is returned if hashing fails.
func SafeGo ¶
func SafeGo(f interface{}, params ...interface{})
SafeGo is a common function to recover panic for goroutines
func StringConcat ¶ added in v2.6.16
func VerifyPassword ¶ added in v2.6.24
VerifyPassword checks the input password against the stored hash. When a legacy MD5 hash is provided, the password is rehashed with bcrypt and the new hash is returned. Any internal bcrypt error is returned.
Types ¶
type B64MathCaptchaProvider ¶ added in v2.6.21
type B64MathCaptchaProvider struct{}
func (B64MathCaptchaProvider) Draw ¶ added in v2.6.21
func (p B64MathCaptchaProvider) Draw(content string) (string, error)
func (B64MathCaptchaProvider) Expiration ¶ added in v2.6.21
func (p B64MathCaptchaProvider) Expiration() time.Duration
type B64StringCaptchaProvider ¶ added in v2.6.21
type B64StringCaptchaProvider struct{}
func (B64StringCaptchaProvider) Draw ¶ added in v2.6.21
func (p B64StringCaptchaProvider) Draw(content string) (string, error)
func (B64StringCaptchaProvider) Expiration ¶ added in v2.6.21
func (p B64StringCaptchaProvider) Expiration() time.Duration
type CaptchaMeta ¶ added in v2.6.21
验证码元数据
type CaptchaProvider ¶ added in v2.6.21
type CaptchaProvider interface { Generate() (id string, content string, answer string, err error) //Validate(ip, code string) bool Expiration() time.Duration // 验证码过期时间, 应该小于 AttemptsWindow Draw(content string) (string, error) // 绘制验证码 }
验证码提供者接口
type LoginLimiter ¶ added in v2.6.21
type LoginLimiter struct {
// contains filtered or unexported fields
}
登录限制器
func NewLoginLimiter ¶ added in v2.6.21
func NewLoginLimiter(policy SecurityPolicy) *LoginLimiter
func (*LoginLimiter) CheckSecurityStatus ¶ added in v2.6.21
func (ll *LoginLimiter) CheckSecurityStatus(ip string) (banned bool, captchaRequired bool)
CheckSecurityStatus 检查安全状态
func (*LoginLimiter) DrawCaptcha ¶ added in v2.6.21
func (ll *LoginLimiter) DrawCaptcha(content string) (err error, str string)
func (*LoginLimiter) RecordFailedAttempt ¶ added in v2.6.21
func (ll *LoginLimiter) RecordFailedAttempt(ip string)
记录登录失败尝试
func (*LoginLimiter) RegisterProvider ¶ added in v2.6.21
func (ll *LoginLimiter) RegisterProvider(p CaptchaProvider)
注册验证码提供者
func (*LoginLimiter) RemoveAttempts ¶ added in v2.6.21
func (ll *LoginLimiter) RemoveAttempts(ip string)
清除记录窗口
func (*LoginLimiter) RequireCaptcha ¶ added in v2.6.21
func (ll *LoginLimiter) RequireCaptcha() (error, CaptchaMeta)
生成验证码
func (*LoginLimiter) VerifyCaptcha ¶ added in v2.6.21
func (ll *LoginLimiter) VerifyCaptcha(id, answer string) bool
验证验证码
Click to show internal directories.
Click to hide internal directories.