Socket
Book a DemoInstallSign in
Socket

stupid_captcha

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stupid_captcha

0.0.2
bundlerRubygems
Version published
Maintainers
1
Created
Source

about

Simple stupid captcha, use it with flash.

how it works

  • Flash ask for captcha, for example at /captcha.json
  • get json with id and img
  • send post with data, captcha_id and captcha_input
  • validate captcha on serwer side
  • save data

settings

create file config/stupid_captcha.rb and set StupidCaptcha settings

use rake secret to generate some good salt

if defined?(StupidCaptcha)
  StupidCaptcha.setup do |config|
    # salt, use rake secret to generate goog salt
    config.salt = "5b213328a3ed873013c553f15......."

    # fonts path, point to directory, default GEM_RROT/assets/fonts
    config.fonts_path = Rails.root.join('artwork/fonts').to_s

    # set fonts array directly (fonts_path is not used), you can find default fonts in GEM_RROT/assets/fonts
    config.fonts = [
      Rails.root.join('artwork/fonts/1.ttf').to_s
    ]

    # backgrounds path, point to directory, default GEM_RROT/assets/backgrounds
    config.backgrounds_path = Rails.root.join('artwork/backgrounds').to_s

    # set backgrounds array directly (backgrounds_path is not used), you can find default fonts in GEM_RROT/assets/backgrounds
    config.backgrounds = [
      Rails.root.join('artwork/backgrounds/1.png').to_s
    ]

    # colors
    config.colors = %w{black}

  end
end

use it

create captcha controller

require 'base64'

class CaptchaController < ApplicationController
  def index
    c = StupidCaptcha::Captcha.new
    c.reset

    respond_to do |wants|
      wants.json  do
        render text: {
          id: c.hash,
          img: Base64.encode64(c.to_blob)
        }.to_json
      end
    end
  end
end

create data controller

class DataController < ApplicationController
  def create
    @data = Data.new(params[:data])

    respond_to do |wants|
      if StupidCaptcha::Captcha.new.check(params[:captcha_id], params[:captcha_input]) && @data.save
        flash[:notice] = 'Data was successfully created.'
        wants.html { redirect_to(@data) }
        wants.xml  { render :xml => @data, :status => :created, :location => @data }
      else
        wants.html { render :action => "new" }
        wants.xml  { render :xml => @data.errors, :status => :unprocessable_entity }
      end
    end
  end
end

routing

get  '/captcha', :controller => "captcha", :action => 'index'
post '/data'   , :controller => "data"   , :action => 'create'

Help

Looking for help?

email to me: lisukorin [at] gmail [dot] com,

don't forget write 'stupid captcha' in subject or my mail client will treat your message as spam.

FAQs

Package last updated on 16 Nov 2011

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.