Coder Social home page Coder Social logo

captcha's Introduction

= Captcha

This captcha generator is based on the very fine work of Eric Methot 
(http://blogs.ericmethot.com/) all credit and thanks should go to him.

This fork allows you to specify a file type for captcha image generation (png or gif).

Using Captcha is a five step process

  1. Install RMagick
  2. Install the plugin 
  3. Generate a bunch of images off-line
  4. Use the helper method(s)
  5. Validate user input

The plugin has been tested on OS X 10.5 using ImageMagick @6.4.1-8_0+q16 (via MacPorts) and
the rmagick 2.5.2 gem.


== Install RMagic

Follow the instructions on their site: 
http://rmagick.rubyforge.org/install-faq.html


== Install the plugin

rails plugin install https://github.com/zendesk/captcha.git
or 
script/plugin install https://github.com/zendesk/captcha.git


== Generate a bunch of images off-line

The reason why you don't need to generate images on the fly is that
they have been generated in advance and all you do is pick one at 
random. 

If you have not used Rails' plugin install mechanism to install the plugin, 
define a salt for your application (otherwise the plugin will take care of that). 
Do this by setting the constant CAPTCHA_SALT to a random string in e.g. your environment.rb
  
   CAPTCHA_SALT = 'Something really random here'

Next, generate the images by running the following rake task, this takes a while:

   rake captcha:generate COUNT=250

This will create the '/public/system/captcha' directory if it doesn't
already exist and put 250 randomly generated captcha images in it.

You can specify the following parameters when running the rake task:

COUNT          - the number of images to generate, default 3
IMAGE_HEIGHT   - the height of the captcha image in pixels, default 50
IMAGE_WIDTH    - the width of the captcha image in pixels, default 260
CAPTCHA_LENGTH - the number of characters in the captcha, default 5
FILE_FORMAT    - the file type of the captcha image (png or gif), default png
FONT_SIZE      - the font size in points, default 44

== Use the helper methods

In your forms all you need to do is:

  <%= captcha_block %>

And add a little bit of CSS styling to get a nice looking captcha validation text field 
and image. If you don't like the way it's setup then use the other helper methods 
(see captcha_helper.rb), which are more granular.


== Validate user input

In your controller, you will need to do the following:

PostController < ApplicationController

   validates_captcha

   def create
      ...
      if captcha_validated?
         ...
      else
         ...
      end
   end
end

That's it.

Copyright (c) 2008 Zendesk, released under the MIT license

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.