application

package
v0.0.0-...-fd23dd1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2019 License: OSL-3.0 Imports: 9 Imported by: 0

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

func (g *Generator) NewCaptcha(length int) *domain.Captcha

NewCaptcha generates a new digit-only captcha with the given length

func (*Generator) NewCaptchaByHash

func (g *Generator) NewCaptchaByHash(hash string) (*domain.Captcha, error)

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

func (g *Generator) NewCaptchaBySolution(solution string) *domain.Captcha

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

func (s *PseudoStore) Inject(
	g *Generator,
)

Inject dependencies

func (*PseudoStore) Set

func (s *PseudoStore) Set(_ string, _ []byte)

Set sets the digits for the captcha id.

type Verifier

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

func (*Verifier) Inject

func (v *Verifier) Inject(
	g *Generator,
)

Inject dependencies

func (*Verifier) Verify

func (v *Verifier) Verify(hash, solution string) bool

Jump to

Keyboard shortcuts

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