honeypot-captcha 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2010 Curtis Miller
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,62 @@
1
+ # honeypot-captcha
2
+
3
+ A simple way to add honeypot captchas in your Rails forms.
4
+
5
+ ## Honeypot Captcha
6
+
7
+ Honeypot captchas work off the premise that you can present different form
8
+ fields to a spam bot than you do to a real user. Spam bots will typically try
9
+ to fill all fields in a form and will not take into account CSS styles.
10
+
11
+ We add bogus fields to a form and then check to see if those fields are
12
+ submitted with values. If they are, we assume that we encountered a spam bot.
13
+
14
+ # Usage
15
+
16
+ I've tried to make it pretty simple to add a honeypot captcha, but I'm open to
17
+ any suggestions you may have.
18
+
19
+ ## form_for
20
+
21
+ Simply specify that the form has a honeypot in the HTML options hash:
22
+
23
+ <% form_for Comment.new, :html => { :honeypot => true } do |form| -%>
24
+ ...
25
+ <% end -%>
26
+
27
+ ## form_tag with block
28
+
29
+ Simply specify that the form has a honeypot in the options hash:
30
+
31
+ <% form_tag comments_path, :honeypot => true do -%>
32
+ ...
33
+ <% end -%>
34
+
35
+ ## form_tag without block
36
+
37
+ Simply specify that the form has a honeypot in the options hash:
38
+
39
+ <%= form_tag comments_path, :honeypot => true -%>
40
+ ...
41
+ </form>
42
+
43
+ ### References
44
+
45
+ * [Honeypot Captcha by Phil Haack](http://haacked.com/archive/2007/09/11/honeypot-captcha.aspx)
46
+ * [Stopping spambots with hashes and honeypots](http://nedbatchelder.com/text/stopbots.html)
47
+
48
+ ## Note on Patches/Pull Requests
49
+
50
+ * Fork the project.
51
+ * Make your feature addition or bug fix.
52
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
53
+ * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
54
+ * Send me a pull request. Bonus points for topic branches.
55
+
56
+ ## Author
57
+
58
+ Written by [Curtis Miller](http://millarian.com) of [Flatterline](http://flatterline.com)
59
+
60
+ ## Copyright
61
+
62
+ Copyright (c) 2010 Curtis Miller. See LICENSE for details.
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "honeypot-captcha"
8
+ gem.summary = %Q{A simple way to add honeypot captchas to Rails forms}
9
+ gem.description = %Q{A simple way to add honeypot captchas to Rails forms}
10
+ gem.email = "curtis@flatterline.com"
11
+ gem.homepage = "http://github.com/curtis/honeypot-captcha"
12
+ gem.authors = ["curtis"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "honeypot-captcha #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,49 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{honeypot-captcha}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["curtis"]
12
+ s.date = %q{2010-04-09}
13
+ s.description = %q{A simple way to add honeypot captchas to Rails forms}
14
+ s.email = %q{curtis@flatterline.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.markdown",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "honeypot-captcha.gemspec",
27
+ "lib/honeypot-captcha.rb",
28
+ "lib/honeypot-captcha/form_tag_helper.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/curtis/honeypot-captcha}
31
+ s.rdoc_options = ["--charset=UTF-8"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.6}
34
+ s.summary = %q{A simple way to add honeypot captchas to Rails forms}
35
+
36
+ if s.respond_to? :specification_version then
37
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
38
+ s.specification_version = 3
39
+
40
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
41
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
42
+ else
43
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
44
+ end
45
+ else
46
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
47
+ end
48
+ end
49
+
@@ -0,0 +1,23 @@
1
+ require 'honeypot-captcha/form_tag_helper'
2
+
3
+ module HoneypotCaptcha
4
+ module SpamProtection
5
+ def honeypot_fields
6
+ [:a_comment_body]
7
+ end
8
+
9
+ def protect_from_spam
10
+ head :ok if honeypot_fields.any? { |f| !params[f].blank? }
11
+ end
12
+
13
+ def self.included(base) # :nodoc:
14
+ base.send :helper_method, :honeypot_fields
15
+
16
+ if base.respond_to? :before_filter
17
+ base.send :prepend_before_filter, :protect_from_spam, :only => [:create, :update]
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ ActionController::Base.send(:include, HoneypotCaptcha::SpamProtection) if defined?(ActionController::Base)
@@ -0,0 +1,33 @@
1
+ # Override the form_tag helper to add honeypot spam protection to forms.
2
+ module ActionView
3
+ module Helpers
4
+ module FormTagHelper
5
+ def form_tag_with_honeypot(url_for_options = {}, options = {}, *parameters_for_url, &block)
6
+ honeypot = options.delete(:honeypot)
7
+ html = form_tag_without_honeypot(url_for_options, options, *parameters_for_url, &block)
8
+ if honeypot
9
+ if block_given?
10
+ html.insert(html.index('</form>'), honey_pot_captcha)
11
+ else
12
+ html += honey_pot_captcha
13
+ end
14
+ end
15
+ html
16
+ end
17
+ alias_method_chain :form_tag, :honeypot
18
+
19
+ private
20
+
21
+ def honey_pot_captcha
22
+ html_ids = []
23
+ honeypot_fields.collect do |f|
24
+ html_ids << (html_id = "#{f}_hp_#{Time.now.to_i}")
25
+ content_tag(:div, send([:text_field_tag, :text_area_tag][rand(2)], f), :id => html_id)
26
+ end.join +
27
+ content_tag(:style, :type => 'text/css', :media => 'screen') do
28
+ "#{html_ids.map { |i| "##{i}" }.join(', ')} { display:none; }"
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: honeypot-captcha
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - curtis
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-09 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
+ version_requirements: *id001
34
+ description: A simple way to add honeypot captchas to Rails forms
35
+ email: curtis@flatterline.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - LICENSE
42
+ - README.markdown
43
+ files:
44
+ - .document
45
+ - .gitignore
46
+ - LICENSE
47
+ - README.markdown
48
+ - Rakefile
49
+ - VERSION
50
+ - honeypot-captcha.gemspec
51
+ - lib/honeypot-captcha.rb
52
+ - lib/honeypot-captcha/form_tag_helper.rb
53
+ has_rdoc: true
54
+ homepage: http://github.com/curtis/honeypot-captcha
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options:
59
+ - --charset=UTF-8
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ requirements: []
77
+
78
+ rubyforge_project:
79
+ rubygems_version: 1.3.6
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: A simple way to add honeypot captchas to Rails forms
83
+ test_files: []
84
+