Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the Check function public #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,3 @@ Usage Example
Included with this repo is [example.go](example/example.go), a simple HTTP server which creates the reCaptcha form and tests the input.

See the [instructions](example/README.md) for running the example for more details.

## Donate

If you find this work useful, please consider making a donation:

<a href="bitcoin:14TM4ADKJbaGEi8Qr8dh4KfPBQmjTshkZ2">Bitcoin Donate</a> `14TM4ADKJbaGEi8Qr8dh4KfPBQmjTshkZ2`

![QR code](https://bitref.com/qr.php?data=14TM4ADKJbaGEi8Qr8dh4KfPBQmjTshkZ2)
11 changes: 5 additions & 6 deletions recaptcha.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ const recaptchaServerName = "https://www.google.com/recaptcha/api/siteverify"

var recaptchaPrivateKey string

// check uses the client ip address, the challenge code from the reCaptcha form,
// Check uses 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 check(remoteip, response string) (r RecaptchaResponse, err error) {
// It returns a RecaptchaResponse object wich contains user response.
func Check(remoteip, response string) (r RecaptchaResponse, err error) {
resp, err := http.PostForm(recaptchaServerName,
url.Values{"secret": {recaptchaPrivateKey}, "remoteip": {remoteip}, "response": {response}})
if err != nil {
Expand All @@ -53,13 +53,12 @@ func check(remoteip, response string) (r RecaptchaResponse, err error) {
return
}

// Confirm is the public interface function.
// It calls check, which the client ip address, the challenge code from the reCaptcha form,
// Confirm 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 Confirm(remoteip, response string) (result bool, err error) {
resp, err := check(remoteip, response)
resp, err := Check(remoteip, response)
result = resp.Success
return
}
Expand Down