recaptcha

package module
v0.0.0-...-e8026af Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2019 License: MIT Imports: 7 Imported by: 0

README

go-recaptcha

About

This package handles reCaptcha (API version 3.0) form submissions in Go.

Usage

Install the package in your environment:

go get github.com/moiteiro/go-recaptcha

To use it within your own code, import github.com/moiteiro/go-recaptcha and call:

recaptcha.Init(recaptchaPrivateKey, recaptchaScore)

once, to set the reCaptcha private key for your domain, then:

recaptcha.Confirm(recaptchaResponse)

for each reCaptcha form input you need to check, using the values obtained by reading the form's POST parameters (the recaptchaResponse in the above corresponds to the value of g-recaptcha-response sent by the reCaptcha server.)

The recaptcha.Confirm() function returns true if the captcha was completed correctly and the score was equal or above the value passed in reCaptcha.Init() or false if the captcha had an invalid token or the score failed, along with any errors (from the HTTP io read or the attempt to unmarshal the JSON reply).

Usage Example

Included with this repo is example.go, a simple HTTP server which creates the reCaptcha form and tests the input.

See the instructions for running the example for more details.

Disclaimer

This project was forked from dpapathanasiou github repository and modified to reCaptcha V3 requests.

Documentation

Overview

Package recaptcha handles reCaptcha (http://www.google.com/recaptcha) form submissions

This package is designed to be called from within an HTTP server or web framework which offers reCaptcha form inputs and requires them to be evaluated for correctness

Edit the recaptchaPrivateKey constant before building and using

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Confirm

func Confirm(response string) (result bool, err error)

Confirm is the public interface function. It calls check, which the client ip address, the challenge code from the reCaptcha form, and the client's response input to that challenge to determine whether or not the client answered the reCaptcha input question correctly. It returns a boolean value indicating whether or not the client answered correctly.

func Init

func Init(key string, score float32)

Init allows the webserver or code evaluating the reCaptcha form input to set the reCaptcha private key (string) value, which will be different for every domain.

Types

type RecaptchaResponse

type RecaptchaResponse struct {
	Success     bool      `json:"success"`
	Score       float32   `json:"score"`
	ChallengeTS time.Time `json:"challenge_ts"`
	Hostname    string    `json:"hostname"`
	ErrorCodes  []string  `json:"error-codes"`
}

Directories

Path Synopsis
example.go
example.go

Jump to

Keyboard shortcuts

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