mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 20:50:54 +00:00
Update captcha.go
Captcha must be deleted if the user entered a "challenge" with a different length than the captcha.
This commit is contained in:
parent
2773fda883
commit
58ac0d5ea4
@ -200,7 +200,7 @@ func (c *Captcha) Verify(id string, challenge string) (success bool) {
|
|||||||
|
|
||||||
key := c.key(id)
|
key := c.key(id)
|
||||||
|
|
||||||
if v, ok := c.store.Get(key).([]byte); ok && len(v) == len(challenge) {
|
if v, ok := c.store.Get(key).([]byte); ok {
|
||||||
chars = v
|
chars = v
|
||||||
} else {
|
} else {
|
||||||
return
|
return
|
||||||
@ -211,6 +211,9 @@ func (c *Captcha) Verify(id string, challenge string) (success bool) {
|
|||||||
c.store.Delete(key)
|
c.store.Delete(key)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if len(chars) != len(challenge) {
|
||||||
|
return
|
||||||
|
}
|
||||||
// verify challenge
|
// verify challenge
|
||||||
for i, c := range chars {
|
for i, c := range chars {
|
||||||
if c != challenge[i]-48 {
|
if c != challenge[i]-48 {
|
||||||
@ -221,6 +224,7 @@ func (c *Captcha) Verify(id string, challenge string) (success bool) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// create a new captcha.Captcha
|
// create a new captcha.Captcha
|
||||||
func NewCaptcha(urlPrefix string, store cache.Cache) *Captcha {
|
func NewCaptcha(urlPrefix string, store cache.Cache) *Captcha {
|
||||||
cpt := &Captcha{}
|
cpt := &Captcha{}
|
||||||
|
Loading…
Reference in New Issue
Block a user