Module: SimpleCaptchaGuard::CaptchaHelper

Defined in:
lib/simple_captcha_guard/captcha_helper.rb

Instance Method Summary collapse

Instance Method Details

#captcha_tagObject



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

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



16
17
18
# File 'lib/simple_captcha_guard/captcha_helper.rb', line 16

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