Skip to content

deepfryed/fastcaptcha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastcaptcha is another image captcha solution. It's simple and very fast.

INSTALL:
  
  sudo gem install fastcaptcha

REQUIREMENT:

  * ruby >= 1.9.1
  * ruby development libraries (debian: ruby1.9.1-dev)
  * opencv >= 2.1.0 development libraries (debian: libcv-dev libhighgui-dev)

USAGE:

  >> require 'fastcaptcha'
  >> captcha = FastCaptcha.new # defaults to redis for caching and low complexity captchas.
  >> challenge = captcha.generate
  >> puts challenge.key
  >> puts challenge.image # PNG image data

  >> require 'fastcaptcha'
  >> require 'moneta/memcache'
  >> captcha = FastCaptcha.new(Moneta::Memcache.new, 3) # use memcached instead & level 3 complexity
  >> challenge = captcha.generate
  >> puts challenge.key
  >> puts challenge.image # PNG image data


SINATRA HELPER:

  * This adds a simple sinatra helper to display and validate captcha. Uses JQuery, so tough luck if you're
    using another Javascript library (patches welcome). If you're not using sinatra, you should be.

  Add the sinatra helper to your application:

  require 'sinatra/captcha'
  class MyApp < Sinatra::Base
    # ttl of captcha before user has to respond.
    set :captcha_ttl, 30

    # complexity 1 is simple, 4 is wicked hard (makes segmentation very difficult).
    set :captcha_level, 2

    # use memcached instead of redis (default).
    # set :captcha_cache, Moneta::Memcache

    register Sinatra::Captcha
  end

  Add the captcha to your form using the captcha helper:

  captcha(ajax: true, id: 'captcha_div')

  Validate the captcha on form submission:

  if captcha_correct?
    do_something
  else
    do_something_else
  end

  You can have multiple captchas in the same page within different <form> elements. Just make sure captcha
  element ids are unique.


LICENSE:

GNU GPLv3, so its free and comes with no guarantees. If it brings down your website or burns down your house, I will
not be held responsible. Use it at your own risk. You can read all about GNU here: http://www.gnu.org and
GNU GPLv3 here: http://www.gnu.org/licenses/gpl.txt.