simple_captcha_guard 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 851f28c627a713cad8109d104ae07e848c10f41c78c83dad22868d7ffe373613
4
+ data.tar.gz: 760eece5b558de34cf3dadd9c45d62a46a69dfb85b25074bf171160d322d91b0
5
+ SHA512:
6
+ metadata.gz: 5874720c9564e7aec2983c08912629dc61d73a8702625f9c0eabef9f127f085fcbab3d681df0daa32e696cafec9c5b097db6ad07f81c9b09ea97d85ffb4e5187
7
+ data.tar.gz: 300fcc972e3399319206f8c5a83b23fbab1c9871802efea4a89ac91f3447f7d2f4b9a92ac30955bd0228dda997b4bdc5c0a5672b022340814736698b982e35c8
@@ -0,0 +1,40 @@
1
+ require "mini_magick"
2
+ require "securerandom"
3
+ require "base64"
4
+ require "stringio"
5
+
6
+ module SimpleCaptchaGuard
7
+ class Captcha
8
+ attr_reader :code
9
+
10
+ def initialize(length = 5)
11
+ @code = SecureRandom.alphanumeric(length).upcase
12
+ end
13
+
14
+ def generate_image
15
+ MiniMagick::Tool::Convert.new do |convert|
16
+ convert.size "121x41"
17
+ convert.gravity "center"
18
+ convert.xc "white"
19
+ convert.fill "black"
20
+ convert.font "Helvetica"
21
+ convert.pointsize "29"
22
+ convert.draw "text 0,0 '#{@code}'"
23
+ color_map = { 1 => "green", 2 => "red", 3 => "blue", 4 => "orange"}
24
+ # Add random lines (5 lines)
25
+ stroke_count = rand(5..7)
26
+ stroke_count.times do
27
+ convert.stroke "#{color_map[rand(1..4)]}" # line color
28
+ convert.strokewidth "#{rand(2)}" # line thickness
29
+ x1, y1 = rand(40), rand(40)
30
+ x2, y2 = rand(65..120), rand(40)
31
+ convert.draw "line #{x1},#{y1} #{x2},#{y2}"
32
+ end
33
+ convert.wave "3x50"
34
+ convert << "png:-" # Output to stdout (returns binary blob)
35
+
36
+ end.to_blob
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,20 @@
1
+ module SimpleCaptchaGuard
2
+ module CaptchaHelper
3
+ def captcha_tag
4
+ captcha = SimpleCaptchaGuard::Captcha.new
5
+ session[:rewsna_ahctpac] = captcha.code.reverse
6
+
7
+ blob = captcha.generate_image
8
+ puts "Generated CAPTCHA code: #{captcha.code}"
9
+ puts "Blob size: #{blob.bytesize} bytes"
10
+
11
+ image_data = Base64.strict_encode64(blob)
12
+ raw "<img src='data:image/png;base64,#{image_data}' alt='CAPTCHA'>"
13
+ end
14
+
15
+
16
+ def verify_captcha(input)
17
+ input.to_s.strip.upcase.reverse == session[:rewsna_ahctpac]
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ module SimpleCaptchaGuard
2
+ class Railtie < Rails::Railtie
3
+ initializer "simple_captcha_guard.helpers" do
4
+ ActiveSupport.on_load(:action_view) do
5
+ include SimpleCaptchaGuard::CaptchaHelper
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ require "simple_captcha_guard/captcha"
2
+ require "simple_captcha_guard/captcha_helper"
3
+ require "simple_captcha_guard/railtie" if defined?(Rails)
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_captcha_guard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Ahmed Mahir Tazwar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-06-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mini_magick
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.11'
27
+ description: A simple CAPTCHA system to block bots in Rails apps.
28
+ email: tazwarutshas@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/simple_captcha_guard.rb
34
+ - lib/simple_captcha_guard/captcha.rb
35
+ - lib/simple_captcha_guard/captcha_helper.rb
36
+ - lib/simple_captcha_guard/railtie.rb
37
+ homepage: https://github.com/Utshas/simple-captcha-guard
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '3.0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubygems_version: 3.5.11
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Simple CAPTCHA gem for Rails
60
+ test_files: []