Module: Asciiptcha::ControllerHelpers

Defined in:
lib/asciiptcha/controller_helpers.rb

Instance Method Summary collapse

Instance Method Details

#asciiptcha_verify(field_id = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/asciiptcha/controller_helpers.rb', line 4

def asciiptcha_verify(field_id = nil)
  if Asciiptcha.config.encryption_key.nil?
    raise EncryptionKeyNotSet, "Encryption key is not set"
  end
  field_id ||= 'asciiptcha_input'
  code_field_id = field_id+"_code"
  if params[field_id].nil? || params[field_id].length < 1 || params[code_field_id].nil? || params[code_field_id].length < 1
    return false
  end

  begin
    decrypted_code = Asciiptcha::aes_decrypt(params[code_field_id],Asciiptcha.config.encryption_key)
  rescue
    return false
  end
  if decrypted_code.downcase == params[field_id].downcase
    return true
  end
  return false
end