You are here: Browse Railsplugins Brain Buster
Note: http://www.robsanheim.com/brain-buster is the home for BrainBuster – please bookmark it for further information and updates. You can see the plugin in action at http://madisonrails.com.
BrainBuster is a logic captcha for Rails. A logic captcha attempts to detect automated responses (ie spambots) by asking a simple quesiton, such as a word puzzle or math question. Logic captchas are often easier for humans to answer then image based captchas, but can exclude foreign users or users with cognitive disabilities. Another possible issue is that answers could be scripted fairly easily by a determined spammer, but I’m guessing in most cases spammers will move on to easier targets. Generating thousands of questions may also deter scripting.
Some example question and answers are:
“What is fifteen minus five?” => “10” “Which one of these doesn’t fit? ‘blue, red, yellow, flower’” => ‘flower’ “Spell the word ‘dog’ backwards.” => “god”
For more on logic captchas and alternate approaches, please see http://www.w3.org/TR/turingtest/#logic
BrainBuster includes a model for storing questions and answers, a module to be mixed in to controllers to help in checking the captcha, a small partial to display the question and input form, and a basic stylesheet for styling the partial. There are many pieces because this plugin spans all of MVC, but each piece is simple and trivial so overriding or replacing certain parts would be easy.
This captcha is meant to be user-friendly, so for a questions like “What is two plus two”, all of the following answers will work: “4”, “four”, “Four”, ” four ”. By default, a user only needs to answer a captcha once, then they are cookied and don’t have to answer another question until they close/reopen their browser.
Note that I did use tests to drive the development of this thing, the problem is extracting the tests so they work in the plugin environment =).
script/generate brain_buster_migration
cp vendor/plugins/brain_buster/assets/stylesheets/captcha.css public/stylesheets/ cp vendor/plugins/brain_buster/assets/partials/_captcha.rhtml app/views/shared/ <%= stylesheet_link_tag ‘captcha’ %>
class AccountController
include BrainBusterMixin
...
class AccountController include BrainBusterMixin
- new.rhtml: ... inside your form somewhere <%= render :partial => ‘shared/captcha’ %>
class AccountController ... def create unless captcha_passed? redirect to :action => ‘new’ and return end ## normal create processing follows… @account = Account.new(params[:account]) ## etc… end ...
BrainBuster is by Rob Sanheim (http://www.robsanheim.com). Email: rsanheim at gmail DOT com
Thanks to the creators of the Exception Logger plugin (http://svn.techno-weenie.net/projects/plugins/exception_logger/) and the Unobtrusive Javascript plugin (http://www.ujs4rails.com/), as I referred to their source code for help.
NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly