honeypot-captcha 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +22 -21
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/honeypot-captcha.gemspec +2 -5
- data/lib/honeypot-captcha.rb +2 -2
- data/lib/honeypot-captcha/form_tag_helper.rb +12 -8
- metadata +5 -18
data/README.markdown
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
#
|
1
|
+
# Honeypot Captcha
|
2
2
|
|
3
3
|
A simple way to add honeypot captchas in your Rails forms.
|
4
4
|
|
5
|
-
## Honeypot Captcha
|
6
|
-
|
7
5
|
Honeypot captchas work off the premise that you can present different form
|
8
6
|
fields to a spam bot than you do to a real user. Spam bots will typically try
|
9
7
|
to fill all fields in a form and will not take into account CSS styles.
|
@@ -11,39 +9,38 @@ to fill all fields in a form and will not take into account CSS styles.
|
|
11
9
|
We add bogus fields to a form and then check to see if those fields are
|
12
10
|
submitted with values. If they are, we assume that we encountered a spam bot.
|
13
11
|
|
14
|
-
|
12
|
+
* [Honeypot Captcha by Phil Haack](http://haacked.com/archive/2007/09/11/honeypot-captcha.aspx)
|
13
|
+
* [Stopping spambots with hashes and honeypots](http://nedbatchelder.com/text/stopbots.html)
|
14
|
+
|
15
|
+
|
16
|
+
## Usage
|
15
17
|
|
16
18
|
I've tried to make it pretty simple to add a honeypot captcha, but I'm open to
|
17
19
|
any suggestions you may have.
|
18
20
|
|
19
|
-
|
21
|
+
### form_for
|
20
22
|
|
21
23
|
Simply specify that the form has a honeypot in the HTML options hash:
|
22
24
|
|
23
|
-
<% form_for Comment.new, :html => { :honeypot => true } do |form| -%>
|
24
|
-
|
25
|
-
<% end -%>
|
25
|
+
<% form_for Comment.new, :html => { :honeypot => true } do |form| -%>
|
26
|
+
...
|
27
|
+
<% end -%>
|
26
28
|
|
27
|
-
|
29
|
+
### form_tag with block
|
28
30
|
|
29
31
|
Simply specify that the form has a honeypot in the options hash:
|
30
32
|
|
31
|
-
<% form_tag comments_path, :honeypot => true do -%>
|
32
|
-
|
33
|
-
<% end -%>
|
33
|
+
<% form_tag comments_path, :honeypot => true do -%>
|
34
|
+
...
|
35
|
+
<% end -%>
|
34
36
|
|
35
|
-
|
37
|
+
### form_tag without block
|
36
38
|
|
37
39
|
Simply specify that the form has a honeypot in the options hash:
|
38
40
|
|
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)
|
41
|
+
<%= form_tag comments_path, :honeypot => true -%>
|
42
|
+
...
|
43
|
+
</form>
|
47
44
|
|
48
45
|
## Note on Patches/Pull Requests
|
49
46
|
|
@@ -57,6 +54,10 @@ Simply specify that the form has a honeypot in the options hash:
|
|
57
54
|
|
58
55
|
Written by [Curtis Miller](http://millarian.com) of [Flatterline](http://flatterline.com)
|
59
56
|
|
57
|
+
### Contributors
|
58
|
+
|
59
|
+
* [Eric Saxby](http://github.com/sax)
|
60
|
+
|
60
61
|
## Copyright
|
61
62
|
|
62
63
|
Copyright (c) 2010 Curtis Miller. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ begin
|
|
10
10
|
gem.email = "curtis@flatterline.com"
|
11
11
|
gem.homepage = "http://github.com/curtis/honeypot-captcha"
|
12
12
|
gem.authors = ["curtis"]
|
13
|
-
gem.add_development_dependency "rspec", ">= 1.2.9"
|
13
|
+
# gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
14
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
15
|
end
|
16
16
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/honeypot-captcha.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{honeypot-captcha}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["curtis"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-05-23}
|
13
13
|
s.description = %q{A simple way to add honeypot captchas to Rails forms}
|
14
14
|
s.email = %q{curtis@flatterline.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -38,12 +38,9 @@ Gem::Specification.new do |s|
|
|
38
38
|
s.specification_version = 3
|
39
39
|
|
40
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
41
|
else
|
43
|
-
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
44
42
|
end
|
45
43
|
else
|
46
|
-
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
47
44
|
end
|
48
45
|
end
|
49
46
|
|
data/lib/honeypot-captcha.rb
CHANGED
@@ -3,11 +3,11 @@ require 'honeypot-captcha/form_tag_helper'
|
|
3
3
|
module HoneypotCaptcha
|
4
4
|
module SpamProtection
|
5
5
|
def honeypot_fields
|
6
|
-
|
6
|
+
{ :a_comment_body => 'Do not fill in this field' }
|
7
7
|
end
|
8
8
|
|
9
9
|
def protect_from_spam
|
10
|
-
head :ok if honeypot_fields.any? { |f| !params[f].blank? }
|
10
|
+
head :ok if honeypot_fields.any? { |f,l| !params[f].blank? }
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.included(base) # :nodoc:
|
@@ -6,10 +6,11 @@ module ActionView
|
|
6
6
|
honeypot = options.delete(:honeypot)
|
7
7
|
html = form_tag_without_honeypot(url_for_options, options, *parameters_for_url, &block)
|
8
8
|
if honeypot
|
9
|
+
captcha = "".respond_to?(:html_safe) ? honey_pot_captcha.html_safe : honey_pot_captcha
|
9
10
|
if block_given?
|
10
|
-
html.insert(html.index('</form>'),
|
11
|
+
html.insert(html.index('</form>'), captcha)
|
11
12
|
else
|
12
|
-
html +=
|
13
|
+
html += captcha
|
13
14
|
end
|
14
15
|
end
|
15
16
|
html
|
@@ -20,13 +21,16 @@ module ActionView
|
|
20
21
|
|
21
22
|
def honey_pot_captcha
|
22
23
|
html_ids = []
|
23
|
-
honeypot_fields.collect do |f|
|
24
|
+
honeypot_fields.collect do |f, l|
|
24
25
|
html_ids << (html_id = "#{f}_hp_#{Time.now.to_i}")
|
25
|
-
content_tag
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
content_tag :div, :id => html_id do
|
27
|
+
content_tag(:style, :type => 'text/css', :media => 'screen', :scoped => "scoped") do
|
28
|
+
"#{html_ids.map { |i| "##{i}" }.join(', ')} { display:none; }"
|
29
|
+
end +
|
30
|
+
label_tag(f, l) +
|
31
|
+
send([:text_field_tag, :text_area_tag][rand(2)], f)
|
32
|
+
end
|
33
|
+
end.join
|
30
34
|
end
|
31
35
|
end
|
32
36
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- curtis
|
@@ -14,23 +14,10 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-05-23 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
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
|
19
|
+
dependencies: []
|
20
|
+
|
34
21
|
description: A simple way to add honeypot captchas to Rails forms
|
35
22
|
email: curtis@flatterline.com
|
36
23
|
executables: []
|