Skip to content

Commit fe343a6

Browse files
authored
feat: adjust captcha verification method (#12946)
1 parent 205f12e commit fe343a6

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

core/utils/captcha/captcha.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package captcha
22

33
import (
4+
"image/color"
45
"strings"
56

67
"github.com/1Panel-dev/1Panel/core/app/dto"
@@ -9,6 +10,16 @@ import (
910

1011
var store = base64Captcha.DefaultMemStore
1112

13+
const (
14+
captchaWidth = 160
15+
captchaHeight = 48
16+
captchaNoise = 0
17+
)
18+
19+
var captchaFonts = []string{
20+
base64Captcha.FontRitaSmith,
21+
}
22+
1223
func VerifyCode(codeID string, code string) string {
1324
vv := store.Get(codeID, true)
1425
vv = strings.TrimSpace(vv)
@@ -23,14 +34,15 @@ func VerifyCode(codeID string, code string) string {
2334
}
2435

2536
func CreateCaptcha() (*dto.CaptchaResponse, error) {
26-
var driverString base64Captcha.DriverString
27-
driverString.Source = "1234567890QWERTYUPLKJHGFDSAZXCVBNMqwertyupkjhgfdsazxcvbnm"
28-
driverString.Width = 120
29-
driverString.Height = 50
30-
driverString.NoiseCount = 0
31-
driverString.Length = 4
32-
driverString.Fonts = []string{"RitaSmith.ttf", "actionj.ttf", "chromohv.ttf"}
33-
driver := driverString.ConvertFonts()
37+
driver := base64Captcha.NewDriverMath(
38+
captchaHeight,
39+
captchaWidth,
40+
captchaNoise,
41+
0,
42+
&color.RGBA{R: 246, G: 248, B: 251, A: 255},
43+
nil,
44+
captchaFonts,
45+
)
3446
c := base64Captcha.NewCaptcha(driver, store)
3547
id, b64s, _, err := c.Generate()
3648
if err != nil {

0 commit comments

Comments
 (0)