This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
413 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Gemfile.lock | ||
pkg/ | ||
tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
language: ruby | ||
bundler_args: --without test | ||
rvm: | ||
- 1.8.7 | ||
- 1.9.3 | ||
- ree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.