Skip to content

Instantly share code, notes, and snippets.

@DarkLotus
Created July 10, 2014 04:35
Show Gist options
  • Select an option

  • Save DarkLotus/8c703ce3ecbc174d95ad to your computer and use it in GitHub Desktop.

Select an option

Save DarkLotus/8c703ce3ecbc174d95ad to your computer and use it in GitHub Desktop.
Contact Enhanced Math Captcha
jQuery(document).ready(function($){
var mathenticate = {
bounds: {
lower: 5,
upper: 50
},
first: 0,
second: 0,
generate: function () {
this.first = Math.floor(Math.random() * this.bounds.lower) + 1;
this.second = Math.floor(Math.random() * this.bounds.upper) + 1;
},
show: function () {
return this.first + ' + ' + this.second;
},
solve: function () {
return this.first + this.second;
}
};
mathenticate.generate();
var $auth = $('<input type="text" name="auth" />');
$auth.attr('placeholder', mathenticate.show())
.insertAfter('textarea[name="message"]');
$('form[name="emailForm"]').on('submit', function (e) {
if ($auth.val() != mathenticate.solve()) {
e.preventDefault();
alert('wrong answer!');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment