Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

captcha

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

captcha

  • 1.2.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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.

FAQs

Package last updated on 29 Nov 2009

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc