All Projects → wenlng → go-captcha

wenlng / go-captcha

Licence: MIT license
Go Captcha is a behavioral captcha, which implements the generation of random verification text and the verification of click position information.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to go-captcha

2captcha-python
Python 3 package for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, hcaptcha, funcaptcha, geetest and solve any other captchas.
Stars: ✭ 140 (+62.79%)
Mutual labels:  captcha, clickcaptcha, funcaptcha, keycaptcha
2captcha-php
PHP package for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, hcaptcha, funcaptcha, geetest and solve any other captchas.
Stars: ✭ 25 (-70.93%)
Mutual labels:  captcha, clickcaptcha, funcaptcha, keycaptcha
2captcha-go
Golang Module for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, hcaptcha, funcaptcha, geetest and solve any other captchas.
Stars: ✭ 31 (-63.95%)
Mutual labels:  captcha, clickcaptcha, funcaptcha, keycaptcha
Raid-Protect-Discord-Bot
A Discord Bot that allows you to protect your Discord server with captcha, anti profanity, anti nudity image, anti spam, account age required, logs...
Stars: ✭ 182 (+111.63%)
Mutual labels:  captcha, captcha-generator
jcaptcha
可扩展java验证码工具类。支持字母,中文,数字运算;同时可配置验证码尺寸,背景色,干扰项
Stars: ✭ 33 (-61.63%)
Mutual labels:  captcha, verification-code
VerificationCode
简单的滑动验证码JS插件 图片验证码
Stars: ✭ 15 (-82.56%)
Mutual labels:  verify, code
cs-wordpress-bouncer
CrowdSec is an open-source cyber security tool. This plugin blocks detected attackers or display them a captcha to check they are not bots.
Stars: ✭ 25 (-70.93%)
Mutual labels:  captcha, captcha-generator
captcha-canvas
A captcha generator by using skia-canvas.
Stars: ✭ 40 (-53.49%)
Mutual labels:  captcha, captcha-generator
captcha-generator
An NPM package to generate captcha images that can be used in Discord bots or various other projects
Stars: ✭ 45 (-47.67%)
Mutual labels:  captcha, captcha-generator
Julia
Algorithms implemented in the Julia programming language. We're collaborating with the Humans of Julia community!
Stars: ✭ 216 (+151.16%)
Mutual labels:  code
SwiftyCodeView
Fully customizable UI Component for verification codes written in swift with RxSwift support!
Stars: ✭ 86 (+0%)
Mutual labels:  code
ax-editor
Ax is a code editor with syntax highlighting that runs in your terminal written completely in Swift.
Stars: ✭ 42 (-51.16%)
Mutual labels:  code
imagetyperz-api-python3
imagetyperz-api-python3 - is a super easy to use bypass captcha API wrapper for imagetyperz.com captcha service
Stars: ✭ 25 (-70.93%)
Mutual labels:  captcha
Z-Spider
一些爬虫开发的技巧和案例
Stars: ✭ 33 (-61.63%)
Mutual labels:  captcha
ConductOfCode
Code examples for the blog
Stars: ✭ 15 (-82.56%)
Mutual labels:  code
email-checker
Provides email verification on the go.
Stars: ✭ 116 (+34.88%)
Mutual labels:  verify
Captcha-Tools
All-in-one Python (And now Go!) module to help solve captchas with Capmonster, 2captcha and Anticaptcha API's!
Stars: ✭ 23 (-73.26%)
Mutual labels:  captcha
django-rest-captcha
No description or website provided.
Stars: ✭ 25 (-70.93%)
Mutual labels:  captcha
Discord-Nitro-BruteForce
simple discord nitro code generator and checker written in c#
Stars: ✭ 26 (-69.77%)
Mutual labels:  code
parse-cloud-class
Extendable way to set up Parse Cloud classes behaviour
Stars: ✭ 40 (-53.49%)
Mutual labels:  code

Go Captcha

Behavioral Captcha


English | 中文

Go Captcha is a behavioral captcha, which implements the generation of random verification text and the verification of click position information.

⭐️ If it helps you, please give a star.


Reward Support

Reward Support

Installation of proxy go module in China

Set Proxy of go module

  • Window
$ set GO111MODULE=on
$ set GOPROXY=https://goproxy.io,direct

### The Golang 1.13+ can be executed directly
$ go env -w GO111MODULE=on
$ go env -w GOPROXY=https://goproxy.io,direct
  • Linux or Mac
$ export GO111MODULE=on
$ export GOPROXY=https://goproxy.io,direct

### or
$ echo "export GO111MODULE=on" >> ~/.profile
$ echo "export GOPROXY=https://goproxy.cn,direct" >> ~/.profile
$ source ~/.profile

Dependency Library

$ go get -u github.com/golang/freetype
$ go get -u golang.org/x/crypto
$ go get -u golang.org/x/image

Install Captcha Module

$ go get -u github.com/wenlng/go-captcha/captcha

Import Captcha Module

package main

import "github.com/wenlng/go-captcha/captcha"

func main(){
   // ...
}

Quick Use

package main
import (
    "fmt"
    "github.com/wenlng/go-captcha/captcha"
)

func main(){
    // Captcha Single Instances
    capt := captcha.GetCaptcha()
    
    // Generate Captcha
    dots, b64, tb64, key, err := capt.Generate()
    if err != nil {
        panic(err)
        return
    }
    
    // Main image base64 code
    fmt.Println(len(b64))
    
    // Thumb image base64 code
    fmt.Println(len(tb64))
    
    // Only key
    fmt.Println(key)
    
    // Dot data For verification
    fmt.Println(dots)
}

Captcha Instances

  • New Instances or Get Single Instances
package main
import (
    "fmt"
    "github.com/wenlng/go-captcha/captcha"
)

func main(){
	// Captcha Instances
    // capt := captcha.NewCaptcha() 
    
    // Captcha Single Instances
    capt := captcha.GetCaptcha()

    // ====================================================
    fmt.Println(capt)

}

Set Configuration

After version v1.2.3, the default size of large drawing is 300×240px, the default size of the small drawing is 150×40px.

Set Chars

Some fonts are attached by default. If other Chinese strings are set, you may need to import a font file.

package main
import (
    "fmt"
    "github.com/wenlng/go-captcha/captcha"
)

func main(){
    capt := captcha.GetCaptcha()
    
    // ====================================================
    // Method: SetRangChars (chars []string) error;
    // Desc: Set random char of captcha
    // ====================================================
    // Letter
    //chars := "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    //_ = capt.SetRangChars(strings.Split(chars, ""))
    
    // Two Letter
    //chars := []string{"HE","CA","WO","NE","HT","IE","PG","GI","CH","CO","DA"}
    //_ = capt.SetRangChars(chars)

    // Chinese Char
    chars := []string{"你","好","呀","这","是","点","击","验","证","码","哟"}
    _ = capt.SetRangChars(chars)

    // ====================================================
    fmt.Println(capt)
}

Set Font File Configuration

You can copy the resource files under the "https://github.com/wenlng/go-captcha-example/tree/main/resources" to the directory of your project.

package main
import (
    "fmt"
    "os"
    "github.com/wenlng/go-captcha/captcha"
)

func main(){
    capt := captcha.GetCaptcha()
    
    path, _ := os.Getwd()    
    // ====================================================
    // Method: SetFont(fonts []string);
    // Desc: Set random font of captcha text
    // ====================================================
    capt.SetFont([]string{
        path + "/__example/resources/fonts/fzshengsksjw_cu.ttf",
    })
}

Set Big Image Configuration

Tip: Some images are attached by default.

package main
import (
    "fmt"
    "golang.org/x/image/font"
    "os"
    "github.com/wenlng/go-captcha/captcha"
)

func main(){
    capt := captcha.GetCaptcha()
    
    path, _ := os.Getwd()    
    // ====================================================
    // Method: SetBackground(color []string);
    // Desc: Set random image of background
    // ====================================================
    capt.SetBackground([]string{
        path + "/__example/resources/images/1.jpg",
        path + "/__example/resources/images/2.jpg",
    })

    // ====================================================
    // Method: SetImageSize(size Size);
    // Desc: Set size of captcha
    // ====================================================
    capt.SetImageSize(captcha.Size{300, 300})

    // ====================================================
    // Method: SetImageQuality(val int);
    // Desc: Set quality of captcha, The compression level ranges from 1 to 5. QualityCompressNone has no compression. The default is the lowest compression level
    // ====================================================
    capt.SetImageQuality(captcha.QualityCompressNone)

    // ====================================================
    // Method: SetFontHinting(val font.Hinting);
    // Desc: Set Hinting of font (HintingNone,HintingVertical,HintingFull)
    // ====================================================
    capt.SetFontHinting(font.HintingFull)

    // ====================================================
    // Method: SetTextRangLen(val captcha.RangeVal);
    // Desc: Set random length of font
    // ====================================================
    capt.SetTextRangLen(captcha.RangeVal{6, 7})

    // ====================================================
    // Method: SetRangFontSize(val captcha.RangeVal);
    // Desc: Set random size of font
    // ====================================================
    capt.SetRangFontSize(captcha.RangeVal{32, 42})

    // ====================================================
    // Method: SetTextRangFontColors(colors []string);
    // Desc: Set random hex color of font
    // ====================================================
    capt.SetTextRangFontColors([]string{
        "#1d3f84",
        "#3a6a1e",
    })
 
    // ====================================================
    // Method: SetImageFontAlpha(val float64);
    // Desc:Set alpha of font
    // ====================================================
    capt.SetImageFontAlpha(0.5)

    // ====================================================
    // Method: SetTextShadow(val bool);
    // Desc:Set shadow of font
    // ====================================================
    capt.SetTextShadow(true)

    // ====================================================
    // Method: SetTextShadowColor(val string);
    // Desc:Set shadow color of font
    // ====================================================
    capt.SetTextShadowColor("#101010")

    // ====================================================
    // Method: SetTextShadowPoint(val captcha.Point);
    // Desc:Set shadow point of font
    // ====================================================
    capt.SetTextShadowPoint(captcha.Point{1, 1})

    // ====================================================
    // Method: SetTextRangAnglePos(pos []captcha.RangeVal);
    // Desc:Set angle of font
    // ====================================================
    capt.SetTextRangAnglePos([]captcha.RangeVal{
        {1, 15},
        {15, 30},
        {30, 45},
        {315, 330},
        {330, 345},
        {345, 359},
    })

    // ====================================================
    // Method: SetImageFontDistort(val int);
    // Desc:Set distort of font
    // ====================================================
    capt.SetImageFontDistort(captcha.DistortLevel2)
}

Set Thumb Image Configuration

Tip: Some images are attached by default.

package main
import (
    "fmt"
    "os"
    "github.com/wenlng/go-captcha/captcha"
)

func main(){
    capt := captcha.GetCaptcha()
    
    path, _ := os.Getwd()    
    
    // ====================================================
    // Method: SetRangCheckTextLen(val captcha.RangeVal);
    // Desc:Set random length of font
    // ====================================================
    capt.SetRangCheckTextLen(captcha.RangeVal{2, 4})

    // ====================================================
    // Method: SetRangCheckFontSize(val captcha.RangeVal);
    // Desc:Set random size of font
    // ====================================================
    capt.SetRangCheckFontSize(captcha.RangeVal{24, 30})
 
    // ====================================================
    // Method: SetThumbTextRangFontColors(colors []string);
    // Desc: Set random hex color of font
    // ====================================================
    capt.SetThumbTextRangFontColors([]string{
        "#1d3f84",
        "#3a6a1e",
    })

    // ====================================================
    // Method: SetThumbBgColors(colors []string);
    // Desc: Sets the random hex color of the background
    // ====================================================
    capt.SetThumbBgColors([]string{
        "#1d3f84",
        "#3a6a1e",
    })

    // ====================================================
    // Method: SetThumbBackground(colors []string);
    // Desc:Set random image of background
    // ====================================================
    capt.SetThumbBackground([]string{
        path + "/__example/resources/images/r1.jpg",
        path + "/__example/resources/images/r2.jpg",
    })

    // ====================================================
    // Method: SetThumbBgDistort(val int);
    // Desc:Set the distort of background
    // ====================================================
    capt.SetThumbBgDistort(captcha.DistortLevel2)

    // ====================================================
    // Method: SetThumbFontDistort(val int);
    // Desc:Set the distort of font
    // ====================================================
    capt.SetThumbFontDistort(captcha.DistortLevel2)

    // ====================================================
    // Method: SetThumbBgCirclesNum(val int);
    // Desc:Sets the number of dots
    // ====================================================
    capt.SetThumbBgCirclesNum(20)

    // ====================================================
    // Method: SetThumbBgSlimLineNum(val int);
    // Desc:Set number of lines
    // ====================================================
    capt.SetThumbBgSlimLineNum(3)
  
}

Other

package main
import (
    "fmt"
    "os"
    "github.com/wenlng/go-captcha/captcha"
)

func main(){
    path, _ := os.Getwd()    
    // ====================================================
    // Method: ClearAssetCacheWithPath(paths []string) bool;
    // Desc: Clear Cache
    // ====================================================
    captcha.ClearAssetCacheWithPaths([]string{
    	path + "/__example/resources/images/1.jpg",
    	path + "/__example/resources/fonts/fonts.ttf",
    })     

    // ====================================================
    // Method: captcha.CheckPointDist(sx, sy, dx, dy, width, height int64) bool;
    // Desc: Check point position
    // ====================================================
    captcha.CheckPointDist(0, 30, 0, 30, 30, 30)    

    // ====================================================
    // Method: captcha.CheckPointDistWithPadding(sx, sy, dx, dy, width, height, padding int64) bool;
    // Desc: Check point position
    // ====================================================
    captcha.CheckPointDistWithPadding(0, 30, 0, 30, 30, 30, 5) 
}

Generate Captcha Data

package main
import (
    "fmt"
    "os"
    "github.com/wenlng/go-captcha/captcha"
)

func main(){
    capt := captcha.GetCaptcha()
    
    // generate ...
    // ====================================================
    // dots:  Character position information
    //  - {"0":{"Index":0,"Dx":198,"Dy":77,"Size":41,"Width":54,"Height":41,"Text":"SH","Angle":6,"Color":"#885500"} ...}
    // imageBase64:  Verify the clicked image
    // thumbImageBase64: Thumb displayed
    // key: Only Key
    // ====================================================
    dots, imageBase64, thumbImageBase64, key, err := capt.Generate()
    if err != nil {
        panic(err)
        return
    }
    fmt.Println(len(imageBase64))
    fmt.Println(len(thumbImageBase64))
    fmt.Println(key)
    fmt.Println(dots)
}

Api Params

// Example: Get captcha data
    Respose Data = {
        "code": 0,
        "image_base64": "...",
        "thumb_base64": "...",
        "captcha_key": "...",
    }     

// Example: Post check data
    Request Data = {
        dots: "x1,y1,x2,y2,...."
        key: "......"
    }

Buy the author coffee: http://witkeycode.com/sponsor


LICENSE

MIT
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].