Module: Kamcaptcha

Defined in:
lib/kamcaptcha.rb,
lib/kamcaptcha/token.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, Token, Validation Classes: Generator

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.pathObject

Returns the value of attribute path.



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

def path
  @path
end

.prefixObject



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

def prefix
  @prefix || ""
end

.saltObject

Returns the value of attribute salt.



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

def salt
  @salt
end

.templateObject

Returns the value of attribute template.



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

def template
  @template
end

Class Method Details

.encrypt(string) ⇒ Object



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

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

.imagesObject



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

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

.randomObject



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

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