Subject: | [Patch included] Fix bug and and small opt |
Hello.
Nice plugin, good job but there is a small bug for that comparing:
[code]
uc($string) eq &{$captcha_string}
[/code]
You can catch bug if run plugin with
[code]
rnd_data => [0...9, 'A'...'Z', 'a'...'z'],
[/code]
Attached patch resolve that problem and add optional feature to make a case sensitive validation.
Please apply patch.
Thank You,
anonymous
Subject: | captcha.patch |
diff --git a/Captcha.pm b/Captcha.pm
index a29541c..c6ef1ef 100644
--- a/Captcha.pm
+++ b/Captcha.pm
@@ -7,7 +7,7 @@ use Mojo::Base 'Mojolicious::Plugin';
use GD::SecurityImage;
-our $VERSION = 0.01;
+our $VERSION = 0.02;
sub register {
my ($self, $app, $conf) = @_;
@@ -40,11 +40,12 @@ sub register {
$app->helper(
validate_captcha => sub {
- my ( $self, $string ) = @_;
- return
- uc($string) eq &{$captcha_string}
- ? 1
- : 0;
+ my ( $self, $string, $case_sens) = @_;
+ !!($case_sens ? (
+ $string eq &{$captcha_string}
+ ) : (
+ uc($string) eq uc(&{$captcha_string})
+ ));
}
);
}
@@ -57,7 +58,7 @@ Mojolicious::Plugin::Captcha - create and validate captcha for Mojolicious frame
=head1 VERSION
-0.01
+0.02
=head1 SYNOPSIS
@@ -109,6 +110,11 @@ Create Captcha image and output it.
Validate captcha string
+ Accept optional second parameter to switch comparator case sensitivity (default is off, i.e. comparator make case insensivity comparing)
+
+ # case sensitivity comparing
+ $self->validate_captcha($self->param('captcha'), 1);
+
=head1 CONFIGURATION
=over 4