gocaptcha

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: May 26, 2015 License: MIT Imports: 26 Imported by: 0

README


View in [English][中文]


gocaptcha

go语言验证码服务器

Build Status Build Status Coverage Status

Feature

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

Useage

安装

go get github.com/hanguofeng/gocaptcha

Quick Start

参考 captcha_test.go

参考 samples/gocaptcha-server

Demo

文档

[captcha.go Wiki]

TODO

  • 运维管理工具

LICENCE

gocaptcha使用[MIT许可协议]

使用的开源软件列表,表示感谢

Documentation

Index

Constants

View Source
const (
	DEFAULT_LIFE_TIME      = time.Minute * 5
	DEFAULT_FONT_SIZE      = 26
	DEFAULT_WIDTH          = 120
	DEFAULT_HEIGHT         = 40
	DEFAULT_GC_PROBABILITY = 1
	DEFAULT_GC_DIVISOR     = 100
)
View Source
const IMAGE_FILTER_NOISE_LINE = "ImageFilterNoiseLine"

ImageFilter is the interface of image filter

View Source
const IMAGE_FILTER_NOISE_POINT = "ImageFilterNoisePoint"
View Source
const IMAGE_FILTER_STRIKE = "ImageFilterStrike"
View Source
const (
	MC_KEY_PREFIX = "gocaptcha-"
)
View Source
const STORE_ENGINE_BUILDIN = "buildin"
View Source
const STORE_ENGINE_MEMCACHE = "memcache"

Variables

This section is empty.

Functions

func RegisterImageFilter

func RegisterImageFilter(id string, f func(FilterConfigGroup) ImageFilter) bool

func RegisterStore

func RegisterStore(name string, f func(*StoreConfig) (StoreInterface, error)) bool

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) error

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) error

LoadDumped file to store

func (*CStore) OnConstruct

func (store *CStore) OnConstruct()

OnConstruct load data

func (*CStore) OnDestruct

func (store *CStore) OnDestruct()

OnDestruct dump data

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, storeConfig *StoreConfig) (*Captcha, error)

CreateCaptcha is a method to create new Captcha struct

func CreateCaptchaFromConfigFile

func CreateCaptchaFromConfigFile(configFile string) (*Captcha, error)

CreateCaptchaFromConfigFile 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, error)

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 {
	LifeTime      time.Duration
	CaseSensitive bool
}

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 CaptchaRedisStore

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

func (*CaptchaRedisStore) Add

func (this *CaptchaRedisStore) Add(captcha *CaptchaInfo) string

func (*CaptchaRedisStore) Del

func (this *CaptchaRedisStore) Del(key string)

func (*CaptchaRedisStore) Destroy

func (this *CaptchaRedisStore) Destroy()

func (*CaptchaRedisStore) Get

func (this *CaptchaRedisStore) Get(key string) *CaptchaInfo

func (*CaptchaRedisStore) OnConstruct

func (this *CaptchaRedisStore) OnConstruct()

func (*CaptchaRedisStore) OnDestruct

func (this *CaptchaRedisStore) OnDestruct()

type FilterConfig

type FilterConfig struct {
	Filters []string
	// contains filtered or unexported fields
}

func (*FilterConfig) GetGroup

func (this *FilterConfig) GetGroup(key string) (FilterConfigGroup, bool)

func (*FilterConfig) Init

func (this *FilterConfig) Init()

func (*FilterConfig) SetGroup

func (this *FilterConfig) SetGroup(key string, group *FilterConfigGroup)

type FilterConfigGroup

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

FilterConfigGroup

func (*FilterConfigGroup) GetItem

func (this *FilterConfigGroup) GetItem(key string) (string, bool)

func (*FilterConfigGroup) Init

func (this *FilterConfigGroup) Init()

func (*FilterConfigGroup) SetItem

func (this *FilterConfigGroup) SetItem(key string, val string)

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)
	GetId() string
	SetConfig(FilterConfigGroup)
	GetConfig() FilterConfigGroup
}

ImageFilter is the interface of image filter

type ImageFilterBase

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

ImageFilter is the base class of image filter

func (*ImageFilterBase) GetConfig

func (filter *ImageFilterBase) GetConfig() FilterConfigGroup

func (*ImageFilterBase) GetId

func (filter *ImageFilterBase) GetId() string

func (*ImageFilterBase) Proc

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

func (*ImageFilterBase) SetConfig

func (filter *ImageFilterBase) SetConfig(config FilterConfigGroup)

type ImageFilterManager

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

ImageFilterManager

func CreateImageFilterManager

func CreateImageFilterManager() *ImageFilterManager

func CreateImageFilterManagerByConfig

func CreateImageFilterManagerByConfig(config *FilterConfig) *ImageFilterManager

func (*ImageFilterManager) AddFilter

func (manager *ImageFilterManager) AddFilter(filter ImageFilter)

func (*ImageFilterManager) GetFilters

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

type ImageFilterNoiseLine

type ImageFilterNoiseLine struct {
	ImageFilterBase
}

func (*ImageFilterNoiseLine) GetId

func (filter *ImageFilterNoiseLine) GetId() string

func (*ImageFilterNoiseLine) Proc

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

Proc the image

type ImageFilterNoisePoint

type ImageFilterNoisePoint struct {
	ImageFilterBase
}

ImageFilter is the interface of image filter

func (*ImageFilterNoisePoint) GetId

func (filter *ImageFilterNoisePoint) GetId() string

func (*ImageFilterNoisePoint) Proc

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

Proc the image

type ImageFilterStrike

type ImageFilterStrike struct {
	ImageFilterBase
}

ImageFilter is the interface of image filter

func (*ImageFilterStrike) GetId

func (filter *ImageFilterStrike) GetId() string

func (*ImageFilterStrike) Proc

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

Proc the image

type MCStore

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

MCStore is the Captcha info store service

func CreateMCStore

func CreateMCStore(expiresTime time.Duration, servers []string) *MCStore

CreateCStore will create a new CStore

func (*MCStore) Add

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

Add captcha info and get the auto generated key

func (*MCStore) Del

func (store *MCStore) Del(key string)

Del captcha info by key

func (*MCStore) Destroy

func (store *MCStore) Destroy()

Destroy the whole store

func (*MCStore) Get

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

Get captcha info by key

func (*MCStore) OnConstruct

func (store *MCStore) OnConstruct()

OnConstruct load data

func (*MCStore) OnDestruct

func (store *MCStore) OnDestruct()

OnDestruct dump data

type StoreConfig

type StoreConfig struct {
	CaptchaConfig
	Engine        string
	Servers       []string
	GcProbability int
	GcDivisor     int
}

StoreConfig ,the store engine config

type StoreInterface

type StoreInterface interface {
	Get(key string) *CaptchaInfo
	Add(captcha *CaptchaInfo) string
	Del(key string)
	Destroy()
	OnConstruct()
	OnDestruct()
}

StoreInterface is the interface of store

func CreateCaptchaRedisStore

func CreateCaptchaRedisStore(config *StoreConfig) (StoreInterface, error)

type WordManager

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

WordManager is a captcha word manage tool

func CreateWordManagerFromDataFile

func CreateWordManagerFromDataFile(filename string) (*WordManager, error)

CreateWordManagerFromDataFile will create a entity from a dictionary file

func (*WordManager) Get

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

Get a specifical length word

func (*WordManager) SetWords

func (mgr *WordManager) SetWords(words []string)

Directories

Path Synopsis
samples
gocaptcha-server
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