A simple captcha implementation for rails 3 based on rmagick
To install easy_captcha
gem install easy_captcha
Add following line to routes.rb
match "captcha" => EasyCaptcha::Controller
You can write this in “config/initializers/easy_captcha.rb”, if you want to customize the default configuration
EasyCaptcha.setup do |config| # 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
<% 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 %>
You find an example app under: github.com/traxanos/easy_captcha_example
-
Marco Scholl (github.com/traxanos)
Copyright © 2010 Marco Scholl, released under the MIT license