Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A Google-style captcha for enterprise Rails apps

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 resources
Octocat-spinner-32 spec
Octocat-spinner-32 tasks Adding captcha:generate rake task March 27, 2009
Octocat-spinner-32 .gitignore Ignoring .DS_Store September 14, 2008
Octocat-spinner-32 MIT-LICENSE Version 1.0.5 March 23, 2009
Octocat-spinner-32 README.markdown
Octocat-spinner-32 Rakefile Compatible with Ruby 1.9.1 November 28, 2009
Octocat-spinner-32 gemspec.rb Compatible with Ruby 1.9.1 November 28, 2009
Octocat-spinner-32 init.rb Adding captcha:generate rake task March 27, 2009
README.markdown

captcha

A Google-style captcha for enterprise Rails apps

Goals

  • Batch generate captchas
  • Use ciphered filenames (no need to store filename/captcha pairs)
  • Easy configuration
    • Number of captchas
    • Period for captcha refresh
    • Colors, wave, implode
  • Handle lots of users

Compatibility

Tested with Ruby 1.8.6, 1.8.7, and 1.9.1.

Install

script/plugin install git://github.com/winton/captcha.git

Create lib/captcha_config.rb (optional)

Captcha::Config.new(
  # Used for filename cipher
  :password => 'something-unique',
  # Captcha colors
  :colors => {
    :background => '#FFFFFF',
    :font => '#080288'
  },
  # Number of captcha images to generate
  :count => RAILS_ENV == 'production' ? 500 : 10,
  # Where to write captchas
  :destination => "#{RAILS_ROOT}/public/images/captchas",
  # Generate new batch every day
  :generate_every => 24 * 60 * 60
)

See lib/captcha/config.rb for more options.

application_controller.rb

class ApplicationController 

You may now use the reset_captcha method in any controller.

user.rb

class User  "base error when captcha fails", :field => "field error when captcha fails"
end

With no parameters, a default error is added to the "captcha" field (:field => true).

Specify :base => true to use a default error for base.

In your view

<img src="/images/captchas/.jpg" />

In your controller

user = User.new
user.known_captcha = session[:captcha]
user.captcha = params[:captcha]
user.save
reset_captcha

crontab

0 0 * * * cd /path/to/rails/app && /usr/bin/rake RAILS_ENV=production captcha:generate

Your config file sets the captcha refresh period. The rake task just checks if its time to repopulate, and does so if necessary.

Something went wrong with that request. Please try again.