EasyCaptcha
A simple captcha implementation for rails 3 based on rmagick
Installation
To install easy_captcha
gem install easy_captcha
Add following line to routes.rb
get :captcha => EasyCaptcha::Controller
Add following line to application_controller.rb
after_filter lambda { session.delete(:captcha) }
The last filter is a critical security measurement! Every request after displaying the captcha-image must prevent this filter from being executed.
Configuration
You can write this in “config/initializers/easy_captcha.rb”, if you want to customize the default configuration
EasyCaptcha.setup do |config|
# Cache
# config.cache = true
# Cache temp dir
# config.temp_dir = Rails.root + 'tmp' + 'captchas'
# Cache size
# config.cache_size = 500
# Cache expire
# config.cache_expire = 1.days
# Chars
# config.chars = %w(2 3 4 5 6 7 9 A C D E F G H J K L M N P Q R S T U X Y Z)
# Length
# config.length = 6
# Font
# config.font_size = 24
# config.font_fill_color = '#333333'
# config.font_stroke_color = '#000000'
# config.font_stroke = 0
# config.font_family = File.expand_path('../../resources/afont.ttf', __FILE__)
# Image
#config.image_height = 40
#config.image_width = 140
#config.image_background_color = "#FFFFFF"
# Wave
# config.wave = true
# config.wave_length = (60..100)
# config.wave_amplitude = (3..5)
# Sketch
# config.sketch = true
# config.sketch_radius = 3
# config.sketch_sigma = 1
# Implode
# config.implode = 0.1
# Blur
# config.blur = true
# config.blur_radius = 1
# config.blur_sigma = 2
end
Example
<% form_tag '/' do %>
<% if request.post? %>
<p><%= valid_captcha?(params[:captcha]) ? 'valid' : 'invalid' %> captcha</p>
<% end %>
<p><%= captcha_tag %></p>
<p><%= text_field_tag :captcha %></p>
<p><%= submit_tag 'Validate' %></p>
<% end %>
Example
You find an example app under: github.com/traxanos/easy_captcha_example
History
* 0.1 Init
* 0.2 Cache support for high frequented sites
Maintainers
-
Marco Scholl (github.com/traxanos)
License
Copyright © 2010 Marco Scholl, released under the MIT license