From f50bcce74e3b8e2827b856ac1472f6e9c4e33aed Mon Sep 17 00:00:00 2001 From: swag Date: Fri, 31 Dec 2021 22:32:39 -0500 Subject: [PATCH] Make CAPTCHA more random --- guestbook-ng.pl | 20 ++++++++++++++++++-- templates/layouts/default.html.ep | 2 +- templates/sign.html.ep | 11 +++++------ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/guestbook-ng.pl b/guestbook-ng.pl index ed49c66..a6992ec 100755 --- a/guestbook-ng.pl +++ b/guestbook-ng.pl @@ -5,9 +5,12 @@ use Mojolicious::Lite -signatures; use Mojo::Pg; +use List::Util qw{shuffle}; +use Data::Dumper; # Uncomment for debugging + +# Load the model use lib 'lib'; use GuestbookNg::Model::Message; -use Data::Dumper; # Uncomment for debugging # Plugins plugin 'Config'; @@ -67,7 +70,20 @@ any [qw{GET POST}], '/sign' => sub ($c) { $c->redirect_to('index'); } else { - $c->render() + my @answers = shuffle(0, 'false', undef); + my $right_answer_label = 'I\'m ready to sign (choose this one)'; + my @wrong_answer_labels = shuffle( + 'I don\'t want to sign (wrong answer)', + 'This is spam/I\'m a bot, do not sign' + ); + + $c->stash( + answers => \@answers, + right_answer_label => $right_answer_label, + wrong_answer_labels => \@wrong_answer_labels + ); + + $c->render(); } }; diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep index 4d9d796..b4f8684 100644 --- a/templates/layouts/default.html.ep +++ b/templates/layouts/default.html.ep @@ -21,7 +21,7 @@
-<%= content %> +<%= content =%>
diff --git a/templates/sign.html.ep b/templates/sign.html.ep index d5fdb03..f8a89cb 100644 --- a/templates/sign.html.ep +++ b/templates/sign.html.ep @@ -16,12 +16,11 @@

SwaggCAPTCHAâ„¢

- <%= radio_button answer => 0 %> - <%= label_for answer => 'I don\'t want to sign (wrong answer)' %> - <%= radio_button answer => 'false' %> - <%= label_for answer => 'I\'m ready to sign (choose this one)' %> - <%= radio_button answer => undef %> - <%= label_for answer => 'This is spam/I\'m a bot, do not sign' %> + <% for my $answer (@$answers) { =%> + <%= radio_button answer => $answer %> + <%= label_for answer => + $answer ? $right_answer_label : pop @$wrong_answer_labels %> + <% } =%>
<%= submit_button 'Sign it', class => 'win95button' %>