hcaptcha

package module
v0.0.0-...-92889e0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: MIT Imports: 10 Imported by: 0

README

go-hcaptcha

About

This package handles hCaptcha form submissions in Go.

Usage

Install the package in your environment:

go get github.com/r7com/go-hcaptcha

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

hcaptcha.Init(recaptchaPrivateKey, recaptchaScore)

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

hcaptcha.Confirm(recaptchaResponse)

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

The hcaptcha.Confirm() function returns true if the captcha was completed correctly and the score was equal or above the value passed in hCaptcha.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).

Documentation

Overview

Package hcaptcha handles hCaptcha (https://hcaptcha.com) form submissions

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

Edit the hcaptchaPrivateKey constant before building and using

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Confirm

func Confirm(response, ip string) (result bool, score float32, err error)

Confirm adds a default context and calls ConfirmWithContext

func ConfirmWithContext

func ConfirmWithContext(ctx context.Context, response string, ip string) (result bool, score float32, err error)

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

func Init

func Init(key string, score float32, time int)

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

Types

type Response

type Response struct {
	Success    bool     `json:"success"`
	Score      float32  `json:"score"`
	Hostname   string   `json:"hostname"`
	ErrorCodes []string `json:"error-codes"`
}

Response holds the response provided by google hcaptcha

Jump to

Keyboard shortcuts

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