Giter VIP home page Giter VIP logo

captcha's Introduction

captcha

A Google-style captcha for enterprise Rails apps

Goals

  • Batch generate captchas
  • Use ciphered filenames (no need to store filename/captcha pairs)
  • Easy configuration
    • Number of captchas
    • Period for captcha refresh
    • Colors, wave, implode
  • Handle lots of users

Compatibility

Tested with Ruby 1.8.6, 1.8.7, and 1.9.1.

Install

script/plugin install git://github.com/winton/captcha.git

Create lib/captcha_config.rb (optional)

Captcha::Config.new(
  # Used for filename cipher
  :password => 'something-unique',
  # Captcha colors
  :colors => {
    :background => '#FFFFFF',
    :font => '#080288'
  },
  # Number of captcha images to generate
  :count => RAILS_ENV == 'production' ? 500 : 10,
  # Where to write captchas
  :destination => "#{RAILS_ROOT}/public/images/captchas",
  # Generate new batch every day
  :generate_every => 24 * 60 * 60
)

See lib/captcha/config.rb for more options.

application_controller.rb

class ApplicationController < ActionController::Base
  acts_as_captcha
end

You may now use the reset_captcha method in any controller.

user.rb

class User < ActiveRecord::Base
  acts_as_captcha :base => "base error when captcha fails", :field => "field error when captcha fails"
end

With no parameters, a default error is added to the "captcha" field (:field => true).

Specify :base => true to use a default error for base.

In your view

<img src="/images/captchas/<%= session[:captcha] %>.jpg" />
<%= text_field_tag(:captcha) %>

In your controller

user = User.new
user.known_captcha = session[:captcha]
user.captcha = params[:captcha]
user.save
reset_captcha

crontab

0 0 * * * cd /path/to/rails/app && /usr/bin/rake RAILS_ENV=production captcha:generate

Your config file sets the captcha refresh period. The rake task just checks if its time to repopulate, and does so if necessary.

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.