No release in over 3 years
Low commit activity in last 3 years
A simple CAPTCHA implementation for Rails 5+ based on RMagick.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 5.0.0
>= 2.13.1
 Project Readme

EasyCAPTCHA

Build Status Maintainability Test Coverage

A simple captcha implementation for Rails 5+ based on RMagick.

This (kandr-easy_captcha) is a fork of EasyCaptcha (easy_captcha) with Rails 5+ support. This fork is maintained by Karl Wilbur/K&R Software (karl@kandrsoftware.com).

Dependencies/Requirements

RMagick should be included in your Gemfile

  gem 'rmagick'

for Java/JRuby you can use

  gem 'rmagick4j'

Installation

add to Gemfile

  gem 'kandr-easy_captcha', require: 'easy_captcha'

after running bundle install, execute

  rails g easy_captcha:install

Configuration

You can configure easy_captcha 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 from Rails.root
    # config.cache_temp_dir          = Rails.root.join('tmp', 'captchas')
    # Cache size
    # config.cache_size              = 500
    # Cache expire
    # config.cache_expire            = 1.day

    # #####
    # # CAPTCHA
    # # Chars available for CAPTCHA
    # config.captcha_character_pool  = %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 of CAPTCHA string
    # config.captcha_character_count = 6
    # config.captcha_character_count_max = 6
    # config.captcha_character_count_min = 6
    #
    # # CAPTCHA Image dimensions
    # config.captcha_image_height    = 40

    #####
    # Image
    # config.captcha_image_height    = 40
    # config.captcha_image_width     = 140

    # #####
    # # eSpeak
    # # Enable eSpeak using all defaults:
    # config.espeak = true

    # # Enable eSpeak using custom config:
    # config.espeak do |espeak|
    #   Amplitude, 0 to 200
    #   espeak.amplitude = 80..120

    #   Word gap. Pause between words
    #   espeak.gap = 80

    #   Pitch adjustment, 0 to 99
    #   espeak.pitch = 30..70

    #   Use voice file of this name from espeak-data/voices
    #   espeak.voice = nil
    # end

    # #####
    # # Generator
    # config.generator :default do |generator|
    #   # # Backgound
    #   # # Ignored (set as `none`) when using custom background image or fill
    #   # generator.background_color = '#FFFFFF'
    #   # An instance of a `Fill` class. RMagick supplies three `Fill` classes:
    #   #    - `HatchFill`
    #   #    - `GradientFill`
    #   #    - `TextureFill`.
    #   generator.background_fill  = nil
    #   # # Custom image to be used for CAPTCHA background
    #   # generator.background_image = nil

    #   # Blur
    #   # generator.blur                   = true
    #   # generator.blur_radius            = 1
    #   # generator.blur_sigma             = 2

    #   # # Font
    #   # generator.font_size              = 24
    #   # generator.font_fill_color        = '#333333'
    #   # generator.font_stroke_color      = '#000000'
    #   # generator.font_stroke            = 0
    #   # generator.font_family            = File.expand_path('../../resources/afont.ttf', __FILE__)

    #   # # Implode  (the "funhouse mirror" effect; negative values allowed)
    #   # generator.implode                = 0.1

    #   # # Sketch
    #   # generator.sketch                 = true
    #   # generator.sketch_radius          = 0.0
    #   # generator.sketch_sigma           = 1.0

    #   # Wave
    #   # generator.wave                   = true
    #   # generator.wave_length            = (60..100)
    #   # generator.wave_amplitude         = (3..5)
    # end
  end

Caching

It is strongly recommended to enable caching. You can see the three paramters which you have to fill in your config file below.

  EasyCaptcha.setup do |config|
    # Cache
    config.cache            = true
    # Cache temp dir from Rails.root
    config.cache_temp_dir   = Rails.root.join('tmp', 'captchas')
    # Cache expire
    config.cache_expire     = 1.day
    # Cache size
    # config.cache_size     = 500
  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 app

You find an example app under: http://github.com/phatworx/easy_captcha_example

History

See the CHANGELOG.md

Maintainers

Contributing to (K&R) EasyCaptcha

  • See the TODO.md file for a list of needed changes
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it!
  • Please do not edit Rakefile, EasyCaptcha::VERSION, or CHANGELOG

Copyright

EasyCAPTCHA is licensed under The MIT License.

Copyright (c) 2010-2021 Marco Scholl; K&R Software, LLC.; and EasyCAPTCHA Contributors. See LICENSE.txt and CHANGELOG.md for further details.