Sha256: fda42cd1eba8a590bc0ae04c1f2e838def7922b51f2a806408a901ac704fff99
Contents?: true
Size: 913 Bytes
Versions: 2
Compression:
Stored size: 913 Bytes
Contents
require 'digest' module TextCaptcha module ActionController include ActionHelper def create_question_captcha @question,@answer = rand_question @answer = Digest::SHA2.hexdigest(@answer.to_s) end def validate_captcha_answer create_question_captcha if captcha_failure? set_captcha_failure_message return false end return true end def captcha_failure? params[:_][:_] != Digest::SHA2.hexdigest(params[:textCaptcha][:answer]) end def set_captcha_failure_message if params[:textCaptcha][:answer].strip == "" flash[:notice] = "<span style='color:red;'>Varification code can't be blank!</span>" else flash[:notice] = "<span style='color:red;'>Wrong Answer, Please enter correct answer!</span>" end end end end ActionController::Base.class_eval { include TextCaptcha::ActionController }
Version data entries
2 entries across 2 versions & 1 rubygems