ASP4x-Captcha-Imager

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

Changes
example/example.png
inc/Module/Install.pm
inc/Module/Install/Base.pm
inc/Module/Install/Can.pm
inc/Module/Install/Fetch.pm
inc/Module/Install/Makefile.pm
inc/Module/Install/Metadata.pm
inc/Module/Install/Win32.pm
inc/Module/Install/WriteAll.pm
lib/ASP4x/Captcha/Imager.pm
Makefile.PL

lib/ASP4x/Captcha/Imager.pm  view on Meta::CPAN

        color   => $color,
        'x'     => ( $idx * $charWidth ) + int(rand() * 8) + $charWidth,
        'y'     => ($img->getheight / 2) + int(rand() * 8) - 4,
      );
    }# end for()
    $img->filter( type => 'gaussian', stddev => 1 );
  }# end for()
  
  # Render the image as PNG:
  my $str = "";
  $img->write(type=>'png', data => \$str)
    or die $img->errstr;
  $Response->Expires( -30 );
  $Response->AddHeader( pragma => 'no-cache' );
  $Response->SetHeader('content-type' => 'image/png');
  $Response->ContentType( 'image/png' );
  $Response->Write( $str );
}# end run()


sub generate_pair
{
  my ($s, $context) = @_;

  my $len = eval { $Config->system->settings->captcha_length } || 4;
  my $chars = join '', ( 'A'..'H', 'J'..'N', 'P'..'Z', 1..9 );

lib/ASP4x/Captcha/Imager.pm  view on Meta::CPAN


"CAPTCHA" is the little security image containing a hard-to-read code that you may
have seen on some websites.  They are common on sign-up forms and email forms.  The
idea is that a bot or script can't read the image and can't guess the code.

C<ASP4x::Captcha::Imager> uses L<Imager> to generate an image of a random string
of numbers and letters.

=head2 What Does the Captcha Image Look Like?

You can see an example in the example/example.png file included with this distribution.

=head2 Recommendations and Considerations

=over 4

=item * Shorter Captchas are probably good enough.

Unless you've got yourself the next Facebook, you could probably get away with
4 characters in your Captcha.  Long captchas will just annoy humans.

t/010-basic/020-basic.t  view on Meta::CPAN

  my $res = $api->ua->get('/handlers/dev.captcha'),
  "Got res"
);

ok(
  length($res->content),
  "Got res.content"
);

is(
  $res->header('content-type') => "image/png",
  "content-type is image/png"
);

my $Session = $api->context->session;

my $wordLength = $api->context->config->system->settings->captcha_length;
my $secret = $api->context->config->system->settings->captcha_key;

my ($word) = grep {
  length($_) == $wordLength &&
  md5_hex($_ . $secret) eq $Session->{asp4captcha}->{$_};



( run in 2.192 seconds using v1.01-cache-2.11-cpan-df04353d9ac )