Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Rewrite. Turning this into a gem.
Browse files Browse the repository at this point in the history
  • Loading branch information
morten committed Sep 11, 2012
1 parent 34ab18c commit 8e960a0
Show file tree
Hide file tree
Showing 25 changed files with 413 additions and 275 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
Gemfile.lock
pkg/
tmp/
6 changes: 6 additions & 0 deletions .travis.yml
@@ -0,0 +1,6 @@
language: ruby
bundler_args: --without test
rvm:
- 1.8.7
- 1.9.3
- ree
8 changes: 8 additions & 0 deletions Gemfile
@@ -0,0 +1,8 @@
source "http://rubygems.org"

group :test do
gem "ruby-debug", "~> 0.10.4", :require => nil, :platforms => :ruby_18
gem "debugger", "~> 1.1.1", :require => nil, :platforms => :ruby_19
end

gemspec
20 changes: 20 additions & 0 deletions MIT-LICENSE.txt
@@ -0,0 +1,20 @@
Copyright (c) 2012 Morten Primdahl

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
105 changes: 0 additions & 105 deletions README

This file was deleted.

52 changes: 52 additions & 0 deletions README.md
@@ -0,0 +1,52 @@
# Kamcaptcha

A captcha system that uses less ridiculous images than ReCAPTCHA. Kamcaptcha has two somewhat independent parts to it, a generator for building the word images to present, and then a runtime configuration for checking validity of what gets submitted.

## Generating images

This is something you do locally, probably just once. You need to generate a series of images for your application to serve, using the kamcaptcha command line tool. The tool depends on RMagick being installed, so:

1. `gem install rmagick`
2. kamcaptcha --help

And then generate the images with your preferences. If you specify a salt, make sure to use that same salt when you configure your application runtime. If you do not specify a salt, kamcaptcha will generate you an appropriate one to use, it looks like this:

```sh
$ kamcaptcha --count 3 /tmp
Generating 3 words into /tmp

1 /tmp/d519172b9cdfb2de5a5b30cf60836defc9b393f0e38a680937fcd5179467b191.png
2 /tmp/a235210981703ca66e6d44450c39d42f40ad482bf165401a485b0d3e6c98e3e8.png
3 /tmp/4ae2941beeea48773243cbf1366520c32dcc7b6375630c0e65bdf313df164ddc.png

Remember to set Kamcaptcha.salt = '58be24c9f6d0293ce2c9316fca1a6ec65d04c9156482b5ae51a267e022ba5a5c' in your application
```

## Runtime configuration

Presumably, Kamcaptcha will be used primarily with Rails, so the following instructions are Rails centric although there's nothing Rails specific about Kamcaptcha.

You need to configure Kamcaptcha in e.g. an initializer:

```ruby
Kamcaptcha.salt = '58be24c9f6d0293ce2c9316fca1a6ec65d04c9156482b5ae51a267e022ba5a5c'
Kamcaptcha.path = File.join(Rails.root, "app", "assets", "images", "kampcaptcha")

# Optionally make use of the included form helper and and validations
ActionController::Base.send(:helper, Kamcaptcha::Helper)
ActionController::Base.send(:include, Kamcaptcha::Validation)
```

You can now use Kamcaptcha in your views:

```ruby
<%= kamcaptcha :label => "Please type in the letters below" %>
```
And in your controllers:
```ruby
return head(:bad_request) unless kamcaptcha_validates?
```
You can write your own helper and controller logic easily, take a look at the source.
12 changes: 12 additions & 0 deletions Rakefile
@@ -0,0 +1,12 @@
require 'bundler/gem_tasks'
require 'rake/testtask'

Rake::TestTask.new do |test|
test.libs << 'lib'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end

task :default do
sh "bundle exec rake test"
end
53 changes: 53 additions & 0 deletions bin/kamcaptcha
@@ -0,0 +1,53 @@
#!/usr/bin/env ruby

require "rubygems"
require "bundler"

require "kamcaptcha"
require "kamcaptcha/generator"

require "trollop"
require "digest"

ARGV << "--help" if ARGV.empty?

opts = Trollop.options do
banner <<-EOS
Captcha word library generator. Builds images of words to present to users.
kamcaptcha [options] <output directory>
Usage examples:
kamcaptcha tmp/
kamcaptcha --count 100 tmp/
kamcaptcha --height 100 --width 300 tmp/
kamcaptcha --length 8 --format gif tmp/
A default run creates a "./tmp" directory and generates 10 random five character word PNG images, each 240x50 pixels in size.
Full list of options:
EOS

opt :salt, "Salt to use, if not specified one will be generated"
opt :count, "How many words to generate", :default => 10
opt :height, "Height of the word image in pixels", :default => 50
opt :width, "Width of the word image in pixesks", :default => 240
opt :length, "Length of the word in number of characters", :default => 5
opt :format, "Image file format", :default => "png"
end

if ARGV.empty? || !File.exist?(ARGV[0])
puts "Output directory does not exist"
exit 1
end

Kamcaptcha.salt = opts[:salt] || Digest::SHA2.hexdigest((0...64).map { rand(150).chr }.join)

puts "Generating #{opts[:count]} words into #{ARGV[0]}\n\n"

opts[:count].times do |i|
puts "\t#{i+1}\t"+Kamcaptcha::Generator.generate(ARGV[0], opts)
end

puts "\nRemember to set Kamcaptcha.salt = '#{Kamcaptcha.salt}' in your application\n"

9 changes: 0 additions & 9 deletions init.rb

This file was deleted.

4 changes: 0 additions & 4 deletions install.rb

This file was deleted.

19 changes: 19 additions & 0 deletions kamcaptcha.gemspec
@@ -0,0 +1,19 @@
Gem::Specification.new "kamcaptcha", "0.0.1" do |s|
s.summary = "A captcha image generator that's a little less retarded"
s.description = "Helps humankind with simpler captchas"
s.authors = [ "Morten Primdahl" ]
s.email = "primdahl@me.com"
s.homepage = "http://github.com/morten/kamcaptcha"
s.files = `git ls-files`.split("\n")
s.license = "MIT"

s.add_runtime_dependency("trollop", ">= 2.0")

s.add_development_dependency("rake")
s.add_development_dependency("bundler")
s.add_development_dependency("rmagick")
s.add_development_dependency("minitest")
s.add_development_dependency("uuidtools", ">= 2.1.3")

s.executables << "kamcaptcha"
end
23 changes: 0 additions & 23 deletions lib/captcha_helper.rb

This file was deleted.

67 changes: 0 additions & 67 deletions lib/captcha_image_generator.rb

This file was deleted.

0 comments on commit 8e960a0

Please sign in to comment.