Negative Captcha Plugin ================ I. What is a Negative Captcha? A negative captcha has the exact same purpose as your run-of-the-mill image captcha: To keep bots from submitting forms. Image ("positive") captchas do this by implementing a step which only humans can do, but bots cannot: read jumbled characters from an image. But this is bad. It creates usability problems, it hurts conversion rates, and it confuses the shit out of lots of people. Why not do it the other way around? Negative captchas create a form that has tasks that only bots can perform, but humans cannot. This has the exact same effect, with (anecdotally) a much lower false positive identification rate when compared with positive captchas. All of this comes without making humans go through any extra trouble to submit the form. It really is win-win. II. How does a Negative Captcha Work? In a negative captcha form there are two main parts and three ancillary parts. I'll explain them thusly. Main Part #1: Honeypots. Honeypots are form fields which look exactly like real form fields. Bots will see them and fill them out. Humans cannot see them and thusly will not fill them out. They are hidden indirectly- usually by positioning them off to the left of the browser. They look kind of like this:
Main Part #2: Real fields. These fields are the ones humans will see, will subsequently fill out, and that you'll pull your real form data out of. The form name will be hashed so that bots will not know what it is. They look kind of like this: Ancillary Part #1: Timestamp This is a field that is used in the hash key to make the hash different on every GET request, and to prevent replayability. Ancillary Part #2: Spinner This is a rotating key that is used in the hash method to prevent replayability. I'm not sold on its usefulness. Ancillary Part #3: Secret key This is simply some key that is used in the hashing method to prevent bots from backing out the name of the field from the hashed field name. III. How does the Negative Captcha Plugin Work? 1) Install the plugin: With Subversion script/plugin install http://code.subwindow.com/negative_captcha With git git submodule add git://github.com/subwindow/negative-captcha.git vendor/plugins/negative_captcha 2) Add in the controller hooks #At top: before_filter :setup_negative_captcha, :only => [:new, :create] #At bottom: private def setup_negative_captcha @captcha = NegativeCaptcha.new( :secret => ::NEGATIVE_CAPTCHA_SECRET, #A secret key entered in environment.rb. 'rake secret' will give you a good one. :spinner => request.remote_ip, :fields => [:name, email, body], #Whatever fields are in your form :params => params) end 3) Modify your POST action(s) to check for the validity of the negative captcha form def create if @captcha.valid? @comment = Comment.create(@captcha.values) #Decrypted params end if @captcha.valid? && @comment.valid? redirect_to @comment else flash[:notice] = @captcha.error render :action => 'new' end end 4) Modify your form to include the honeypots and other fields. You can probably leave any select, radio, and check box fields alone. The text field/text area helpers should be sufficient. <% form_tag comments_path do -%> <%= negative_captcha(@captcha) %>