module StupidCaptcha

Constants

GEM_ROOT
VERSION

Public Class Methods

setup() { |self| ... } click to toggle source
# File lib/stupid_captcha.rb, line 22
def self.setup
  yield self
end

Public Instance Methods

backgrounds() click to toggle source
# File lib/stupid_captcha.rb, line 41
def backgrounds
  @@backgrounds ||= files(backgrounds_path)
end
check(hash, text) click to toggle source
# File lib/stupid_captcha.rb, line 61
def check(hash, text)
  hash.eql?(encrypt(text, salt))
end
encrypt(text, salt) click to toggle source
# File lib/stupid_captcha.rb, line 33
def encrypt(text, salt)
  Digest::SHA1.hexdigest(text+salt)
end
files(path) click to toggle source
# File lib/stupid_captcha.rb, line 50
def files(path)
  array = []
  Dir.foreach(path) do |x|
    file = path+"/"+x
    if File.file?(file)
      array << file
    end
  end
  return array
end
fonts() click to toggle source
# File lib/stupid_captcha.rb, line 37
def fonts
  @@fonts ||= files(fonts_path)
end
random_string( len = 12) click to toggle source
# File lib/stupid_captcha.rb, line 26
def random_string( len = 12)
  chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
  str = ""
  1.upto(len) { |i| str << chars[rand(chars.size-1)] }
  return str
end
salt() click to toggle source
# File lib/stupid_captcha.rb, line 45
def salt
  raise "StupidCaptcha.salt is blank" if @@salt.blank?
  @@salt
end