The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Captcha::reCAPTCHA - A Perl implementation of the reCAPTCHA API

VERSION

This document describes Captcha::reCAPTCHA version 0.98

NOTICE

Please note this module now allows the use of v2 there are no changes to version 1. Version 2 has seperate methds you can call

SYNOPSIS

Note this release contains methods that use

    use Captcha::reCAPTCHA;

    my $c = Captcha::reCAPTCHA->new;

    # Output form New Version
    print $c->get_html_v2( 'your public key here' );

    # Version 1 (not recommended)
    print $c->get_html( 'your public key here' );

    # Verify submission
    my $result $c->check_answer_v2($private_key, $response, $ENV{REMOTE_ADDR});

    # Verify submission (Old Version)
    my $result = $c->check_answer(
        'your private key here', $ENV{'REMOTE_ADDR'},
        $challenge, $response
    );

    if ( $result->{is_valid} ) {
        print "Yes!";
    }
    else {
        # Error
        $error = $result->{error};
    }

For complete examples see the /examples subdirectory

DESCRIPTION

reCAPTCHA version 1 is a hybrid mechanical turk and captcha that allows visitors who complete the captcha to assist in the digitization of books.

From http://recaptcha.net/learnmore.html:

    reCAPTCHA improves the process of digitizing books by sending words that
    cannot be read by computers to the Web in the form of CAPTCHAs for
    humans to decipher. More specifically, each word that cannot be read
    correctly by OCR is placed on an image and used as a CAPTCHA. This is
    possible because most OCR programs alert you when a word cannot be read
    correctly.

version 1 of Perl implementation is modelled on the PHP interface that can be found here:

http://recaptcha.net/plugins/php/

To use reCAPTCHA you need to register your site here:

https://www.google.com/recaptcha/admin/create

Version 2 is a new and eaasy to solve captcha that is "easy for humans to solve, but hard for 'bots' and other malicious software"

INTERFACE

new

Create a new Captcha::reCAPTCHA.

get_options_setter( $options )

You can optionally customize the look of the reCAPTCHA widget with some JavaScript settings. get_options_setter returns a block of Javascript wrapped in <script> .. </script> tags that will set the options to be used by the widget.

$options is a reference to a hash that may contain the following keys:

theme

Defines which theme to use for reCAPTCHA. Possible values are 'red', 'white' or 'blackglass'. The default is 'red'.

tabindex

Sets a tabindex for the reCAPTCHA text box. If other elements in the form use a tabindex, this should be set so that navigation is easier for the user. Default: 0.

get_options_setter_div( $pubkey, $options )

You can optionally customize the look of the reCAPTCHA widget with some settings. get_options_setter_div returns a div element wrapped in <div> .. </div> tags that will set the options to be used by the widget.

$options is a reference to a hash that may contain the following keys:

data-theme

Defines which theme to use for reCAPTCHA. Possible values are 'dark', 'light'. The default is 'light'.

data-type

Defines the type of captcha to server. Possible values are 'audio' or 'image'. Default is 'image'

data-size

Defines the size of the widget. Possible values are 'compact' or 'normal'. Default is 'normal'

data-tabindex

Defines the tabindex of the widget and challenge. If other elements in your page use tabindex, it should be set to make user navigation easier. Default is 0

data-callback

Defines the name of your callback function to be executed when the user submits a successful CAPTCHA response. The user's response, g-recaptcha-response, will be the input for your callback function.

data-expired-callback

Defines the name of your callback function to be executed when the recaptcha response expires and the user needs to solve a new CAPTCHA

get_html_v2( $pubkey, \%options )

Generates HTML to display the captcha using the new api pubkey is public key for \%options types the same as get_options_setter

  print $captcha->get_html_v2($pubkey, $options);

This uses ssl by default and does not display custom error messages

get_html( $pubkey, $error, $use_ssl, \%options )

Generates HTML to display the captcha using api version 1.

    print $captcha->get_html( $PUB, $err );
$pubkey

Your reCAPTCHA public key, from the API Signup Page

$error

Optional. If set this should be either a string containing a reCAPTCHA status code or a result hash as returned by check_answer.

$use_ssl

Optional. Should the SSL-based API be used? If you are displaying a page to the user over SSL, be sure to set this to true so an error dialog doesn't come up in the user's browser.

$options

Optional. A reference to a hash of options for the captcha. See get_options_setter for more details.

Returns a string containing the HTML that should be used to display the captcha.

check_answer_v2

After the user has filled out the HTML form, including their answer for the CAPTCHA, use check_answer to check their answer when they submit the form. The user's answer will be in field, g-recaptcha-response. The reCAPTCHA library will make an HTTP request to the reCAPTCHA server and verify the user's answer.

$privkey

Your reCAPTCHA private key, from the API Signup Page.

$remoteip

The user's IP address, in the format 192.168.0.1 (optional)

$response

The value of the form field recaptcha_response_field.

Returns a reference to a hash containing two fields: is_valid and error.

    my $result = $c->check_answer_v2(
        'your private key here', $response,
        $ENV{'REMOTE_ADDR'}
    );

    my $result = $c->check_answer_v2(
        'your private key here', $response,
        $ENV{'REMOTE_ADDR'}
    );

    if ( $result->{is_valid} ) {
        print "Yes!";
    }
    else {
        # Error
        $error = $result->{error};
    }

See the /examples subdirectory for examples of how to call check_answer_v2.

Note: this method will make an HTTP request to Google to verify the user input. If this request must be routed via a proxy in your environment, use the standard environment variable to specify the proxy address, e.g.:

    $ENV{http_proxy} = 'http://myproxy:3128';
check_answer

After the user has filled out the HTML form, including their answer for the CAPTCHA, use check_answer to check their answer when they submit the form. The user's answer will be in two form fields, recaptcha_challenge_field and recaptcha_response_field. The reCAPTCHA library will make an HTTP request to the reCAPTCHA server and verify the user's answer.

$privkey

Your reCAPTCHA private key, from the API Signup Page.

$remoteip

The user's IP address, in the format 192.168.0.1.

$challenge

The value of the form field recaptcha_challenge_field

$response

The value of the form field recaptcha_response_field.

Returns a reference to a hash containing two fields: is_valid and error.

    my $result = $c->check_answer(
        'your private key here', $ENV{'REMOTE_ADDR'},
        $challenge, $response
    );

    if ( $result->{is_valid} ) {
        print "Yes!";
    }
    else {
        # Error
        $error = $result->{error};
    }

See the /examples subdirectory for examples of how to call check_answer_v1.

Note: this method will make an HTTP request to Google to verify the user input. If this request must be routed via a proxy in your environment, use the standard environment variable to specify the proxy address, e.g.:

    $ENV{http_proxy} = 'http://myproxy:3128';

CONFIGURATION AND ENVIRONMENT

Captcha::reCAPTCHA requires no configuration files or environment variables.

To use reCAPTCHA sign up for a key pair here:

https://www.google.com/recaptcha/admin/create

DEPENDENCIES

LWP::UserAgent, HTML::Tiny

INCOMPATIBILITIES

None reported .

BUGS AND LIMITATIONS

Please see below link

https://rt.cpan.org/Public/Dist/Display.html?Name=Captcha-reCAPTCHA

Please report any bugs or feature requests to bug-captcha-recaptcha@rt.cpan.org, or through the web interface at http://rt.cpan.org.

AUTHOR

Mainainted by Sunny Patel <sunnypatel4141@gmail.com> Please report all bugs to Sunny Patel

Version 0.95-0.97 was maintained by Fred Moyer <fred@redhotpenguin.com>

Original Author Andy Armstrong <andy@hexten.net>

LICENCE AND COPYRIGHT

Copyright (c) 2007, Andy Armstrong <andy@hexten.net>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.