Documentation ¶
Index ¶
- type CaptchaController
- func (c *CaptchaController) CheckControl(ids []string, ctrl string, validityDuration time.Duration) (bool, error)
- func (c *CaptchaController) DecryptID(dataB64 string) (string, error)
- func (c *CaptchaController) EncryptID(id string) (string, error)
- func (c *CaptchaController) NewChallenge(kind string, lang string) (*Challenge, error)
- func (c *CaptchaController) ResourcePath(id string) (string, error)
- type Challenge
- type ChallengeManager
- type ChallengeType
- type CryptoSource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CaptchaController ¶
type CaptchaController struct {
// contains filtered or unexported fields
}
CaptchaController handle captcha generation and validation
func NewCaptchaController ¶
func NewCaptchaController(challengeManager ChallengeManager, key []byte) *CaptchaController
NewCaptchaController init a captchat controller with provided manager When validating a captcha, you must use the same controller as keys are randomly generated
func (*CaptchaController) CheckControl ¶
func (c *CaptchaController) CheckControl(ids []string, ctrl string, validityDuration time.Duration) (bool, error)
CheckControl validate the user answer with the challenge controle string The user answer needs to be in the order of appearance from the challenge returned by NewChallenge
func (*CaptchaController) DecryptID ¶
func (c *CaptchaController) DecryptID(dataB64 string) (string, error)
DecryptID decrypt the id in order to retrieve the base ID without the random part
func (*CaptchaController) EncryptID ¶
func (c *CaptchaController) EncryptID(id string) (string, error)
EncryptID encrypt an id with a rand part so that successif call to captcha will not yield the same id twice
func (*CaptchaController) NewChallenge ¶
func (c *CaptchaController) NewChallenge(kind string, lang string) (*Challenge, error)
NewChallenge generate a new challenge with provided kind kind will be provided to the callenge manager. You probably want it to be "visual" or "audio"
func (*CaptchaController) ResourcePath ¶ added in v0.0.2
func (c *CaptchaController) ResourcePath(id string) (string, error)
ResourcePath return the path to the resource with the provided ID
type Challenge ¶
type Challenge struct { // Controle is used to validate the user answer Controle string `json:"controle"` // ResourcesID is an ordered list of available answer to choose from ResourcesID []string `json:"resourcesId"` // ChallengeType define what kind of challenge the user needs to answer ChallengeType ChallengeType `json:"challengeType"` }
Challenge contains data for use by the end-user
type ChallengeManager ¶
type ChallengeManager interface { ListChallenges(kind string, lang string) ([]ChallengeType, error) GetGoodAnswerIDs(challenge ChallengeType, count int) ([]string, error) GetBadAnswerIDs(challenge ChallengeType, count int) ([]string, error) GetResourcePath(id string) (string, error) }
ChallengeManager define what challenges are available, provide good and bad answers to challenges as well as resource path
type ChallengeType ¶
type ChallengeType struct { // Kind of challenge. Eg: "visual", "audio" Kind string `json:"kind"` // Metadata related to that challenge. Eg: `"name":"dice throw"`, `"want":"ge-15"` Metadata map[string]string `json:"metadata"` // Any data, more flexible than Metadata Data interface{} `json:"data"` }
ChallengeType define a type of challenge
type CryptoSource ¶
type CryptoSource struct { }
func (CryptoSource) Int63 ¶
func (_ CryptoSource) Int63() int64
func (CryptoSource) Seed ¶
func (_ CryptoSource) Seed(_ int64)