Documentation
¶
Overview ¶
Example ¶
Example generates a new captcha instance and calls the verify process with a wrong and a right solution In reality the solution for the Verify call would be the user input
package main
import (
"fmt"
"flamingo.me/flamingo/core/captcha/application"
)
func main() {
generator := &application.Generator{}
generator.Inject(
&struct {
EncryptionPassPhrase string `inject:"config:captcha.encryptionPassPhrase"`
}{
EncryptionPassPhrase: "example",
},
)
c := generator.NewCaptchaBySolution("123456")
verifier := application.Verifier{}
verifier.Inject(generator)
wrong := verifier.Verify(c.Hash, "654321")
right := verifier.Verify(c.Hash, "123456")
fmt.Println("Wrong:", wrong, "Right:", right)
}
Output: Wrong: false Right: true
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator to create captchas
func (*Generator) Inject ¶
func (g *Generator) Inject( config *struct { EncryptionPassPhrase string `inject:"config:captcha.encryptionPassPhrase"` }, )
Inject dependencies
func (*Generator) NewCaptcha ¶
NewCaptcha generates a new digit-only captcha with the given length
func (*Generator) NewCaptchaByHash ¶
NewCaptchaByHash recreates a captcha by the given hash. The hash must be generated with the same encryption key, normally by the same instance of Generator
func (*Generator) NewCaptchaBySolution ¶
NewCaptchaBySolution creates a new captcha containing the given solution. However, multiple calls with the same solution will have different hashes because the encryption nonce is selected by random
type PseudoStore ¶
type PseudoStore struct {
// contains filtered or unexported fields
}
PseudoStore implements the Store interface of github.com/dchest/captcha by using regeneration by hash
func (*PseudoStore) Get ¶
func (s *PseudoStore) Get(id string, _ bool) []byte
Get returns the original digits from the given hash
func (*PseudoStore) Set ¶
func (s *PseudoStore) Set(_ string, _ []byte)
Set sets the digits for the captcha id.