ASP4x-Captcha-Imager

 view release on metacpan or  search on metacpan

META.yml  view on Meta::CPAN

--- #YAML:1.0
name:               ASP4x-Captcha
version:            0.003
abstract:           Imager-based CAPTCHA for your ASP4 web application.
author:
    - John Drago <jdrago_999@yahoo.com>
license:            perl
distribution_type:  module
test_requires:
    Test::More:       0
requires:
    Carp:             0
    ASP4:             1.046
    Imager:           0.71
no_index:
    directory:
        - t
        - inc

inc/Module/Install/Metadata.pm  view on Meta::CPAN

	$ISCORE  = 1;
	@ISA     = qw{Module::Install::Base};
}

my @scalar_keys = qw{
	name
	module_name
	abstract
	author
	version
	distribution_type
	tests
	installdirs
};

my @tuple_keys = qw{
	configure_requires
	build_requires
	requires
	recommends
	bundles

inc/Module/Install/Metadata.pm  view on Meta::CPAN

	while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) {
		$self->feature( $name, @$mods );
	}
	return $self->{values}{features}
		? @{ $self->{values}{features} }
		: ();
}

sub no_index {
	my $self = shift;
	my $type = shift;
	push @{ $self->{values}{no_index}{$type} }, @_ if $type;
	return $self->{values}{no_index};
}

sub read {
	my $self = shift;
	$self->include_deps( 'YAML::Tiny', 0 );

	require YAML::Tiny;
	my $data = YAML::Tiny::LoadFile('META.yml');

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

        halign  => 'center',
        valign  => 'center',
        string  => $chars[$idx],
        size    => $charHeight,
        image   => $img,
        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;

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

  use vars __PACKAGE__->VARS;

  1;# return true:

=head2 In your ASP Script:

Render the Captcha image:

  <html>
  <head>
  <style type="text/css">
  LABEL {
    display:        block;
    width:          265px;
    text-align:     right;
    float:          left;
    padding-right:  5px;
  }
  
  IMG {
    border: dotted 1px #AAA;
  }
  </style>
  </head>
  <body>
    <form action="/handlers/dev.validate" method="post">
      <p>
        <label>Enter the code you see below:</label>
        <input type="text" name="security_code" />
      </p>
      <p>
        <label>&nbsp;</label>
        <img id="captcha" src="/handlers/dev.captcha?r=<%= rand() %>" alt="Security Code" />
        <a href="" onclick="document.getElementById('captcha').src = '/handlers/dev.captcha?r=' + Math.random(); return false">
          (Click for a new Image)
        </a>
      </p>
      <p>
        <label>&nbsp;</label>
        <input type="submit" value="Submit" />
      </p>
    </form>
  </body>
  </html>

=head2 Validate the Captcha

  package dev::validate;

  use strict;

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}->{$_};

t/htdocs/form.asp  view on Meta::CPAN

<html>
<body>

  <form action="/handlers/dev.validate" method="post">
    <p>
      <label>Enter the code you see below:</label>
      <input type="text" name="security_code" />
    </p>
    <p>
      <label>&nbsp;</label>
      <img id="captcha" src="/handlers/dev.captcha?r=<%= rand() %>" alt="Security Code" />
      <br/>
      <a href="" onclick="document.getElementById('captcha').src = '/handlers/dev.captcha?r=' + Math.random(); return false">
        (Click for a new Image)
      </a>
    </p>
    <p>
      <label>&nbsp;</label>
      <input type="submit" value="Submit" />
    </p>
  </form>

</body>
</html>



( run in 2.428 seconds using v1.01-cache-2.11-cpan-2c0d6866c4f )