public function testCorrect()
 {
     App::uses('CaptchaLib', 'Tools.Lib');
     $Captcha = new CaptchaLib();
     $hash = $Captcha->buildHash(['captcha' => 2, 'captcha_time' => time() - 10, ''], CaptchaLib::$defaults);
     $data = ['title' => 'xyz', 'captcha' => '2', 'homepage' => '', 'captcha_hash' => $hash, 'captcha_time' => time() - 10];
     $this->Comment->set($data);
     $is = $this->Comment->validates();
     //debug($this->Comment->invalidFields());
     $this->assertTrue($is);
 }
示例#2
0
 public function testBuildHash()
 {
     $data = array('captcha_time' => time(), 'captcha' => '2');
     $options = array('salt' => 'xyz', 'checkIp' => true, 'checkSession' => true);
     $res = CaptchaLib::buildHash($data, $options);
     pr($res);
     $this->assertTrue(strlen($res) == 40);
 }
 function load($options = array(), $input = '')
 {
     // Call the parent class load method (includes necessary files)
     CaptchaLib::load();
     // ConfigArray
     $CAPTCHA_INIT = array('tempfolder' => str_replace("\\", "/", $this->getImagePath()) . '/', 'TTF_folder' => $this->getFontPath() . '/', 'TTF_RANGE' => array('FreeSans.ttf', 'FreeSerif.ttf'), 'chars' => (int) $options['chars'], 'minsize' => (int) $options['minsize'], 'maxsize' => (int) $options['maxsize'], 'maxrotation' => (int) $options['maxrotation'], 'noise' => $options['noise'] == '1' ? true : false, 'websafecolors' => $options['websafecolors'] == '1' ? true : false, 'refreshlink' => TRUE, 'lang' => 'en', 'maxtry' => 3, 'badguys_url' => '/', 'secretstring' => $options['secretstring'], 'secretposition' => (int) $options['secretposition'], 'debug' => FALSE, 'counter_filename' => '', 'prefix' => 'hn_captcha_', 'collect_garbage_after' => (int) $options['collect_garbage_after'], 'maxlifetime' => (int) $options['maxlifetime']);
     if (!isset($this->object)) {
         $_POST['hncaptcha_private_key'] = $input;
         $this->object = new hn_captcha_X1($CAPTCHA_INIT);
     }
 }
 function load($options = array())
 {
     // Call the parent class load method (includes necessary files)
     CaptchaLib::load();
     $aFonts = array(cms_join_path($this->getFontPath(), 'FreeSans.ttf'), cms_join_path($this->getFontPath(), 'FreeSerif.ttf'));
     if (!isset($this->object)) {
         $this->object = new PhpCaptcha($aFonts, $options['width'], $options['height']);
         $this->object->DisplayShadow($options['display_shadow'] == '1' ? true : false);
         $this->object->UseColour($options['use_color'] == '1' ? true : false);
         if ($options['owner_text'] != '') {
             $this->object->SetOwnerText($options['owner_text']);
         }
     }
 }
示例#5
0
 /**
  * @param array $captchaCode
  */
 protected function buildHash($data)
 {
     return CaptchaLib::buildHash($data, $this->settings, true);
 }
示例#6
0
 /**
  * CaptchaBehavior::_buildHash()
  *
  * @param array $data
  * @return string Hash
  */
 protected function _buildHash($data)
 {
     return CaptchaLib::buildHash($data, $this->settings[$this->Model->alias]);
 }
 function load()
 {
     if (!$this->checkAvailability()) {
         return;
     }
     // Call the parent class load method (includes necessary files)
     CaptchaLib::load();
     if (!isset($this->object)) {
         $this->object = Text_CAPTCHA::factory('Image');
     }
 }