Module: Kamcaptcha

Defined in:
lib/kamcaptcha.rb,
lib/kamcaptcha/helper.rb,
lib/kamcaptcha/generator.rb,
lib/kamcaptcha/validation.rb

Overview

You must configure Kamcaptcha with a path to the generated words, and a salt. The salt must be the same you used when generating words.

Defined Under Namespace

Modules: Helper, Validation Classes: Generator

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/kamcaptcha.rb', line 8

def path
  @path
end

.saltObject

Returns the value of attribute salt.



8
9
10
# File 'lib/kamcaptcha.rb', line 8

def salt
  @salt
end

Class Method Details

.encrypt(string) ⇒ Object



24
25
26
27
# File 'lib/kamcaptcha.rb', line 24

def self.encrypt(string)
  raise "You must configure a salt" if Kamcaptcha.salt.nil?
  Digest::SHA2.hexdigest("#{salt}::#{string}")
end

.imagesObject



15
16
17
# File 'lib/kamcaptcha.rb', line 15

def self.images
  @images ||= Dir.glob("#{path}/*.*").map { |f| File.basename(f) }
end

.randomObject



11
12
13
# File 'lib/kamcaptcha.rb', line 11

def self.random
  images[rand(images.size)]
end

.valid?(input, validation) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/kamcaptcha.rb', line 19

def self.valid?(input, validation)
  input = input.to_s.delete(" ").downcase
  encrypt(input) == validation
end