Home > slide_captcha

slide_captcha

Slide_captcha is a project mainly written in RUBY and JAVASCRIPT, based on the MIT license.

An interactive alternative to hard-to-read CAPTCHA schemes

=SlideCAPTCHA

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.

==Dependencies

Scriptaculous and Prototype:: http://script.aculo.us Ruby/GD:: http://rubyforge.org/projects/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.

==Setup

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

==Usage

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 tasks

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

==TODO

  • Further customization options
  • Remove requirement for GD and only use RMagic if possible
  • Eventually, use CSS3 for more complicated transformations

Copyright (c) 2010 Pete Hau, released under the MIT license

Previous:bmauth