Module: SimpleCaptchaGuard::CaptchaHelper

Defined in:
lib/simple_captcha_guard/captcha_helper.rb

Class Method Summary collapse

Class Method Details

.captcha_tagObject



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/simple_captcha_guard/captcha_helper.rb', line 5

def captcha_tag
  captcha = SimpleCaptchaGuard::Captcha.new
  session[:rewsna_ahctpac] = captcha.code.reverse

  blob = captcha.generate_image
  puts "Generated CAPTCHA code: #{captcha.code}"
  puts "Blob size: #{blob.bytesize} bytes"

  image_data = Base64.strict_encode64(blob)
  raw "<img src='data:image/png;base64,#{image_data}' alt='CAPTCHA'>"
end

.verify_captcha(input) ⇒ Object



18
19
20
# File 'lib/simple_captcha_guard/captcha_helper.rb', line 18

def verify_captcha(input)
  input.to_s.strip.upcase.reverse == session[:rewsna_ahctpac]
end