gocaptcha

package module
v0.0.0-...-0d211b3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2013 License: MIT Imports: 21 Imported by: 0

README


View in [English][中文]


gocaptcha

go语言验证码服务器

Build Status

Feature

  • 支持中文验证码
  • 支持自定义词库、字库
  • 支持自定义滤镜机制,通过滤镜来增加干扰,加大识别难度
  • 当前的滤镜包括:
    • 支持干扰点
    • 支持干扰线
    • 支持其他模式的干扰
    • 更多模式,可实现imagefilter接口来扩展

Useage

安装

go get github.com/hanguofeng/gocaptcha

Quick Start

参考 captcha_test.go

文档

[captcha.go Wiki]

TODO

  • 支持单机、集群部署
  • 运维管理工具

LICENCE

gocaptcha使用[MIT许可协议]

Bitdeli Badge

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CImage

type CImage struct {
	*image.Paletted
	// contains filtered or unexported fields
}

CImage is a image process tool

func CreateCImage

func CreateCImage(config *ImageConfig) *CImage

CreateCImage will create a CImage struct with config

type CStore

type CStore struct {
	// contains filtered or unexported fields
}

CStore is the Captcha info store service

func CreateCStore

func CreateCStore(expiresTime time.Duration, gcProbability int, gcDivisor int) *CStore

CreateCStore will create a new CStore

func (*CStore) Add

func (store *CStore) Add(captcha *CaptchaInfo) string

Add captcha info and get the auto generated key

func (*CStore) Del

func (store *CStore) Del(key string)

Del captcha info by key

func (*CStore) Destroy

func (store *CStore) Destroy()

Destroy the whole store

func (*CStore) Dump

func (store *CStore) Dump(file string)

Dump the whole store

func (*CStore) Get

func (store *CStore) Get(key string) *CaptchaInfo

Get captcha info by key

func (*CStore) LoadDumped

func (store *CStore) LoadDumped(file string)

LoadDumped file to store

type Captcha

type Captcha struct {
	// contains filtered or unexported fields
}

Captcha is the core captcha struct

func CreateCaptcha

func CreateCaptcha(wordManager *WordManager, captchaConfig *CaptchaConfig, imageConfig *ImageConfig, filterConfig *FilterConfig) *Captcha

CreateCaptcha is a method to create new Captcha struct

func (*Captcha) GetImage

func (captcha *Captcha) GetImage(key string) (image.Image, error)

GetImage will generate the binary image data

func (*Captcha) GetKey

func (captcha *Captcha) GetKey(length int) string

GetKey will generate a key with required length

func (*Captcha) Verify

func (captcha *Captcha) Verify(key, textToVerify string) (bool, string)

Verify will verify the user's input and the server stored captcha text

type CaptchaConfig

type CaptchaConfig struct {
	CaptchaLifeTime time.Duration
	GcProbability   int
	GcDivisor       int
}

CaptchaConfig ,the captcha config

type CaptchaInfo

type CaptchaInfo struct {
	Text       string
	CreateTime time.Time
}

CaptchaInfo is the entity of a captcha text:the content text,for the image display and user to recognize createTime:the time when the captcha is created

type FilterConfig

type FilterConfig struct {
	EnableStrike     bool
	EnableNoisePoint bool
	EnableNoiseLine  bool
	StrikeLineNum    int
	NoisePointNum    int
	NoiseLineNum     int
}

FilterConfig ,the filter config

type FontManager

type FontManager struct {
	// contains filtered or unexported fields
}

FontManager is a Font Manager the manage font list

func CreateFontManager

func CreateFontManager() *FontManager

CreateFontManager will create a new Font Manager

func (*FontManager) AddFont

func (fm *FontManager) AddFont(pathToFontFile string) error

AddFont will add a new font file to the list

func (*FontManager) GetFont

func (fm *FontManager) GetFont(pathToFontFile string) *truetype.Font

GetFont will return a Font struct by path

func (*FontManager) GetRandomFont

func (fm *FontManager) GetRandomFont() *truetype.Font

GetRandomFont will return a random Font struct

type ImageConfig

type ImageConfig struct {
	Width     int
	Height    int
	FontSize  float64
	FontFiles []string
	// contains filtered or unexported fields
}

ImageConfig ,the image config

type ImageFilter

type ImageFilter interface {
	Proc(cimage *CImage)
}

ImageFilter is the interface of image filter

type ImageFilterBase

type ImageFilterBase struct {
}

ImageFilter is the base class of image filter

func (*ImageFilterBase) Proc

func (filter *ImageFilterBase) Proc(cimage *CImage)

type ImageFilterManager

type ImageFilterManager struct {
	// contains filtered or unexported fields
}

ImageFilterManager

func CreateImageFilterManager

func CreateImageFilterManager() *ImageFilterManager

func (*ImageFilterManager) AddFilter

func (manager *ImageFilterManager) AddFilter(filter ImageFilter)

func (*ImageFilterManager) GetFilters

func (manager *ImageFilterManager) GetFilters() []ImageFilter

type ImageFilterNoiseLine

type ImageFilterNoiseLine struct {
	*ImageFilterBase
	NoiseLineNum int
}

ImageFilter is the interface of image filter

func (*ImageFilterNoiseLine) Proc

func (filter *ImageFilterNoiseLine) Proc(cimage *CImage)

Proc the image

type ImageFilterNoisePoint

type ImageFilterNoisePoint struct {
	*ImageFilterBase
	NoisePointNum int
}

ImageFilter is the interface of image filter

func (*ImageFilterNoisePoint) Proc

func (filter *ImageFilterNoisePoint) Proc(cimage *CImage)

Proc the image

type ImageFilterStrike

type ImageFilterStrike struct {
	*ImageFilterBase
	StrikeLineNum int
}

ImageFilter is the interface of image filter

func (*ImageFilterStrike) Proc

func (filter *ImageFilterStrike) Proc(cimage *CImage)

Proc the image

type WordManager

type WordManager struct {
	// contains filtered or unexported fields
}

WordManager is a captcha word manage tool

func (*WordManager) Get

func (mgr *WordManager) Get(length int) string

Get a specifical length word

func (*WordManager) LoadFromFile

func (mgr *WordManager) LoadFromFile(filename string) error

LoadFromFile is the loader func of word manager

Directories

Path Synopsis
samples
http
CServer project main.go
CServer project main.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL