CAPTCHAs getting too hard to read, even for a human? SlideCAPTCHA uses a slightly different approach, using an image with easily-read text (compared with other modern CAPTCHAs), but with one difficulty for bots: the user must move a slider to line the text up properly. Humans can line text up easily even with gaps cut into the font, but bots must transform the image and attempt text recognition multiple times.
- Scriptaculous and Prototype
- Ruby/GD
Scriptaculous slider effects may not be available with all versions of Rails. If this is the case, copy slider.js from the plugin’s public/javascripts to your public/javascripts directory.
Ruby/GD is required for image generation.
Install: script/plugin install git://github.com/jimworm/slide_captcha.git
Create tables: rake db:migrate:slide_captcha:up
Generate codes and images (n=10000, takes about 100s on a 1.83GHz Intel Core 2 Duo with OSX): rake slide_captcha:add_codes
Include SlideCAPTCHA in your forms with the following code:
<%= slide_captcha_tags %>
Verify responses by calling the following in your controller:
verify_slide_captcha(options)
Returns true if verified, false if the response is incorrect. Available options (optional) are :model
:: A model to attach errors to, probably the object of your form. :message
:: A custom error message.
Example usage:
if verify_slide_captcha(:model => @user, :message => “No robots allowed”) @user.save else render :action => :edit end
rake db:migrate:slide_captcha:up rake db:migrate:slide_captcha:down
Creates/drops tables “slide_captcha_codes”, “slide_captcha_sessions”
rake slide_captcha:add_codes length=x n=y rake slide_captcha:reset length=x n=y
Fills table “slide_captcha_codes” with y random codes x characters long, then generates images for all codes in the table. Reset also expires all sessions and deletes all stored codes before proceeding. Default: length=6 n=10000
Note: Creates unique codes only, it’ll not allow you to use up more than 10% of the available codespace.
rake slide_captcha:expire_sessions before=x
Deletes rows in “slide_captcha_sessions” created before x, where x is a string that could be evaluated to a date or time in Rails eg. “10.minutes.ago”, “Date.yesterday”, “Time.now”. Default: before=30.minutes.ago
-
Further customization options
-
Remove requirement for GD and only use RMagic if possible
-
Eventually, use CSS3 for more complicated transformations
Copyright © 2010 Pete Hau, released under the MIT license