3 Star 3 Fork 1

三三物联网 / ssiot-core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
store.go 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
zou qinqin 提交于 2023-03-02 17:42 . 修改模块名
package captcha
import (
"gitee.com/sansaniot/sansan-core/storage"
"github.com/mojocn/base64Captcha"
)
type cacheStore struct {
cache storage.AdapterCache
expiration int
}
// NewCacheStore returns a new standard memory store for captchas with the
// given collection threshold and expiration time (duration). The returned
// store must be registered with SetCustomStore to replace the default one.
func NewCacheStore(cache storage.AdapterCache, expiration int) base64Captcha.Store {
s := new(cacheStore)
s.cache = cache
s.expiration = expiration
return s
}
// Set sets the digits for the captcha id.
func (e *cacheStore) Set(id string, value string) {
_ = e.cache.Set(id, value, e.expiration)
}
// Get returns stored digits for the captcha id. Clear indicates
// whether the captcha must be deleted from the store.
func (e *cacheStore) Get(id string, clear bool) string {
v, err := e.cache.Get(id)
if err == nil {
if clear {
_ = e.cache.Del(id)
}
return v
}
return ""
}
//Verify captcha's answer directly
func (e *cacheStore) Verify(id, answer string, clear bool) bool {
return e.Get(id, clear) == answer
}
1
https://gitee.com/sansaniot/ssiot-core.git
git@gitee.com:sansaniot/ssiot-core.git
sansaniot
ssiot-core
ssiot-core
v1.5.0

搜索帮助