登录失败次数限制

This commit is contained in:
LinskRuis.32 2020-10-24 14:26:54 +08:00
parent 31523beac5
commit 1fc6dd755b
2 changed files with 30 additions and 3 deletions

View File

@ -59,9 +59,9 @@ function main(){
`,
}
HookjsMap["github"] = &Hookjs{
Uis: map[string]string{"secretkey": "string", "branch": "string"},
Desc: "secretkey:签名秘钥,branch:push对象分支",
Defs: `{"secretkey":"pwd","branch":"master"}`,
Uis: map[string]string{"password": "string", "branch": "string"},
Desc: "password:签名秘钥,branch:push对象分支",
Defs: `{"password":"pwd","branch":"master"}`,
js: `
function main(){

View File

@ -27,6 +27,13 @@ func LoginInfo(c *gin.Context) {
c.JSON(200, rets)
}
type lgTimes struct {
times int
lgtm time.Time
}
var mplgtms = make(map[string]*lgTimes)
func Login(c *gin.Context, req *ruisUtil.Map) {
name := req.GetString("name")
pass := req.GetString("pass")
@ -39,10 +46,30 @@ func Login(c *gin.Context, req *ruisUtil.Map) {
c.String(511, "未找到用户!")
return
}
tms, ok := mplgtms[usr.Xid]
if ok && time.Since(tms.lgtm).Minutes() < 10 {
if tms.times >= 2 {
c.String(521, "失败次数太多,十分钟后再试!")
return
}
}
if usr.Pass != ruisUtil.Md5String(pass) {
if ok {
tms.times++
tms.lgtm = time.Now()
if tms.times > 2 {
tms.times = 1
}
} else {
mplgtms[usr.Xid] = &lgTimes{
times: 0,
lgtm: time.Now(),
}
}
c.String(512, "密码错误!")
return
}
delete(mplgtms, usr.Xid)
tks, err := core.CreateToken(&jwt.MapClaims{
"xid": usr.Xid,