Skip to content

Validate Google reCAPTCHA v2 & v3 form submission package in golang

License

Notifications You must be signed in to change notification settings

ezzarghili/recaptcha-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

recaptcha-go

Build Status

Google reCAPTCHA v2 form submittion in golang

Usage

Install the package in your environment

go get github.com/ezzarghili/recaptcha-go

To use it within your own code

import "github.com/ezzarghili/recaptcha-go"
func main(){
    captcha := recaptcha.NewReCAPTCHA(recaptchaSecret) // get your secret from https://www.google.com/recaptcha/admin
}

Now everytime you need to verify a client request use

success, err := captcha.Verify(recaptchaResponse, ClientRemoteIP)
if err !=nil {
    // do something with err (log?)
}
// proceed with success (true|false)

or

success, err := captcha.VerifyNoRemoteIP(recaptchaResponse)
if err !=nil {
    // do something with err (log?)
}
// proceed with success (true|false)

while recaptchaResponse is the form value with name g-recaptcha-response sent back by recaptcha server and set for you in the form when user answers the challenge

Both recaptcha.Verify and recaptcha.VerifyNoRemoteIP return a bool and error values (bool, error)

Use the error to check for issues with the secret and connection in the server, and use the bool value to verify if the client answered the challenge correctly

Run Tests

Use the standard go means of running test.

go test

Issues with this library

If you have some problems with using this library, bug reports or enhancement please open an issue in the issues tracker.

License

Let's go with something permitive should we ?

MIT