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

NAME

Dancer::Plugin::Captcha::SecurityImage - generate and verify GD::SecurityImage captchas from Dancer

SYNOPSIS

    use Dancer;
    use Dancer::Plugin::Captcha::SecurityImage;
    
    session 'simple';
    
    get '/captcha' => sub {
        create_captcha {
            new => {
                width    => 80,
                height   => 30,
                lines    => 10,
                gd_font  => 'giant',
            },
            create     => [ normal => 'rect' ],
            particle   => [ 100 ],
            out        => { force => 'jpeg' },
            random     => $your_random_string,
        };
    };
    
    post '/verify' => sub {
        my $p = request->params;
        
        if (!validate_captcha $p->{captcha}) {
            return "wrong code";
        }
        clear_captcha;
    };

ABSTRACT

This plugin lets you use GD::SecurityImage in your Dancer application to create and verify captcha codes. It stores captcha data in your session, so you have to enable a session engine for Dancer.

EXPORTED FUNCTIONS

create_captcha

This function expects a hashref containing options that will be passed to the GD::SecurityImage constructor and methods.

validate_captcha

This function expects the value that your user entered in the form. It will check it against the real code stored in the Dancer session and return true if they match.

clear_captcha

This function will remove the captcha value from your session data so that it won't match again.

CONFIGURATION

Any option passed to the create_captcha function, except for random, can also be put in your config file:

    plugins:
      SecurityImage:
        new:
          width: 80
          height: 30
          lines: 10
          gd_font: giant

SEE ALSO

Dancer
GD::SecurityImage

BUGS

Please report any bugs to the web interface at https://rt.cpan.org/Public/Bug/Report.html?Queue=Dancer-Plugin-Captcha-SecurityImage. The author will be happy to read your feedback.

AUTHOR

Alessandro Ranellucci <aar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Alessandro Ranellucci.

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