예제 #1
0
 public function check($name, $captcha)
 {
     $saved = session()->pull('image_captcha.' . $name);
     if (empty($captcha) || empty($saved)) {
         return false;
     }
     $builder = new CaptchaBuilder($saved);
     return $builder->testPhrase($captcha);
 }
예제 #2
0
 /**
  * Validate input phrase
  *
  * @access  public
  * @param   array   $userInput  User input phrase
  * @return  string
  */
 public function validate($userInput)
 {
     // Validate time
     if (!$this->isAlive()) {
         // Regenerate builder
         $this->regenerate();
         return false;
     }
     // Validate using builder
     return $this->builder->testPhrase($userInput);
 }
예제 #3
0
 public function captcha(Model $Model, $check)
 {
     $value = array_values($check);
     $value = $value[0];
     $field = key($check);
     if (CakeSession::check('captcha')) {
         $builder = new CaptchaBuilder();
         $builder->setPhrase(CakeSession::read('captcha'));
         if ($builder->testPhrase($value)) {
             return true;
         }
     }
     return false;
 }
 /**
  * Validate captcha
  *
  * @access protected
  * @param  array   $values           Form values
  * @return boolean
  */
 protected function validateCaptcha(array $values)
 {
     $errors = array();
     if (!isset($this->sessionStorage->captcha)) {
         $result = false;
     } else {
         $builder = new CaptchaBuilder();
         $builder->setPhrase($this->sessionStorage->captcha);
         $result = $builder->testPhrase(isset($values['captcha']) ? $values['captcha'] : '');
         if (!$result) {
             $errors['captcha'] = array(t('Invalid captcha'));
         }
     }
     return array($result, $errors);
 }
예제 #5
0
 /**
  * Test if a given phrase is valid (ie: same as in session).
  * If yes, return true.
  * If not, revoke the captcha and return false.
  */
 public function isValid($phrase)
 {
     if (!is_string($phrase)) {
         return false;
     }
     if (!$this->session->has($this->sessionKey)) {
         return false;
     }
     $captcha = $this->session->get($this->sessionKey);
     if (!isset($captcha['phrase'])) {
         return false;
     }
     $builder = new CaptchaBuilder($captcha['phrase']);
     if (!$builder->testPhrase($phrase)) {
         $this->revoke();
         return false;
     }
     return true;
 }
예제 #6
0
 /**
  * Validate captcha
  *
  * @access protected
  * @param  array   $values           Form values
  * @return boolean
  */
 protected function validateCaptcha(array $values)
 {
     $result = true;
     $errors = array();
     if ($this->userLockingModel->hasCaptcha($values['username'])) {
         if (!isset($this->sessionStorage->captcha)) {
             $result = false;
         } else {
             $builder = new CaptchaBuilder();
             $builder->setPhrase($this->sessionStorage->captcha);
             $result = $builder->testPhrase(isset($values['captcha']) ? $values['captcha'] : '');
             if (!$result) {
                 $errors['login'] = t('Invalid captcha');
             }
         }
     }
     return array($result, $errors);
 }
예제 #7
0
 /**
  * Validate captcha
  *
  * @access public
  * @param  array   $values           Form values
  * @return boolean
  */
 public function validateFormCaptcha(array $values)
 {
     if ($this->hasCaptcha($values['username'])) {
         $builder = new CaptchaBuilder();
         $builder->setPhrase($this->session['captcha']);
         return $builder->testPhrase(isset($values['captcha']) ? $values['captcha'] : '');
     }
     return true;
 }
예제 #8
0
 public function captchaAction()
 {
     $builder = new CaptchaBuilder();
     $builder->build();
     if ($builder->testPhrase($userInput)) {
         // instructions if user phrase is good
     } else {
         // user phrase is wrong
     }
     header('Content-type: image/jpeg');
     $builder->output();
 }
예제 #9
0
 public function captcha()
 {
     $builder = new CaptchaBuilder();
     $builder->build();
     Session::set('captcha', $builder->getPhrase());
     if ($builder->testPhrase(Session::get('captcha'))) {
         // instructions if user phrase is good
     } else {
         // user phrase is wrong
     }
     header('Content-type: image/jpeg');
     $builder->output();
 }