Make CAPTCHA more random

This commit is contained in:
swag 2021-12-31 22:32:39 -05:00
parent 4420202d5f
commit f50bcce74e
3 changed files with 24 additions and 9 deletions

View File

@ -5,9 +5,12 @@
use Mojolicious::Lite -signatures; use Mojolicious::Lite -signatures;
use Mojo::Pg; use Mojo::Pg;
use List::Util qw{shuffle};
use Data::Dumper; # Uncomment for debugging
# Load the model
use lib 'lib'; use lib 'lib';
use GuestbookNg::Model::Message; use GuestbookNg::Model::Message;
use Data::Dumper; # Uncomment for debugging
# Plugins # Plugins
plugin 'Config'; plugin 'Config';
@ -67,7 +70,20 @@ any [qw{GET POST}], '/sign' => sub ($c) {
$c->redirect_to('index'); $c->redirect_to('index');
} }
else { 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();
} }
}; };

View File

@ -21,7 +21,7 @@
</center> </center>
</div> </div>
<div class="inner"> <div class="inner">
<%= content %> <%= content =%>
</div> </div>
<div class="outer"> <div class="outer">
<footer> <footer>

View File

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