update: Adding interference to CAPTCHA
This commit is contained in:
parent
06a2425474
commit
bc721b0ba6
@ -3,6 +3,7 @@ package captcha
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mojocn/base64Captcha"
|
"github.com/mojocn/base64Captcha"
|
||||||
@ -15,8 +16,18 @@ type localService struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newLocalService(redisClient *redis.Client) Service {
|
func newLocalService(redisClient *redis.Client) Service {
|
||||||
// Configure captcha driver
|
// Configure captcha driver - alphanumeric with visual effects (letters + numbers)
|
||||||
driver := base64Captcha.NewDriverDigit(80, 240, 5, 0.7, 80)
|
driver := base64Captcha.NewDriverString(
|
||||||
|
80, // height
|
||||||
|
240, // width
|
||||||
|
20, // noise count (more interference)
|
||||||
|
base64Captcha.OptionShowSlimeLine|base64Captcha.OptionShowSineLine, // show curved lines
|
||||||
|
5, // length (5 characters)
|
||||||
|
"abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789", // source (exclude confusing chars)
|
||||||
|
nil, // bg color (use default)
|
||||||
|
nil, // fonts (use default)
|
||||||
|
nil, // fonts storage (use default)
|
||||||
|
)
|
||||||
return &localService{
|
return &localService{
|
||||||
redis: redisClient,
|
redis: redisClient,
|
||||||
driver: driver,
|
driver: driver,
|
||||||
@ -61,8 +72,8 @@ func (s *localService) Verify(ctx context.Context, id string, code string, ip st
|
|||||||
// Delete captcha after verification (one-time use)
|
// Delete captcha after verification (one-time use)
|
||||||
s.redis.Del(ctx, key)
|
s.redis.Del(ctx, key)
|
||||||
|
|
||||||
// Verify code
|
// Verify code (case-insensitive)
|
||||||
return answer == code, nil
|
return strings.EqualFold(answer, code), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *localService) GetType() CaptchaType {
|
func (s *localService) GetType() CaptchaType {
|
||||||
@ -94,5 +105,5 @@ func (r *redisStore) Get(id string, clear bool) string {
|
|||||||
|
|
||||||
func (r *redisStore) Verify(id, answer string, clear bool) bool {
|
func (r *redisStore) Verify(id, answer string, clear bool) bool {
|
||||||
v := r.Get(id, clear)
|
v := r.Get(id, clear)
|
||||||
return v == answer
|
return strings.EqualFold(v, answer)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user