/**
  * Check if the Captcha result is good
  * @return Mixed
  */
 public function send()
 {
     $session = new SessionCaptcha();
     $captcha = new Captcha($session);
     $frontendData = $captcha->getFrontendData();
     if (!$frontendData) {
         return Lang::get('error.captcha.none');
     } else {
         // If an image field name was submitted, try to validate it
         if ($imageAnswer = Input::get($frontendData['imageFieldName'])) {
             if ($captcha->validateImage($imageAnswer)) {
                 // Return false if the result is correct
                 return false;
             } else {
                 return Lang::get('error.captcha.image');
             }
         } else {
             if ($audioAnswer = Input::get($frontendData['audioFieldName'])) {
                 if ($captcha->validateAudio($audioAnswer)) {
                     // Return false if the result is correct
                     return false;
                 } else {
                     return Lang::get('error.captcha.audio');
                 }
             } else {
                 return Lang::get('error.captcha.incomplete');
             }
         }
     }
 }
Beispiel #2
0
 /**
  * Vérifie un email
  * @return object 2 attributs, bool success et array string msg
  */
 private function check()
 {
     $std = (object) array('success' => false, 'msg' => array());
     if (!$_SESSION['user']) {
         if (($res = Membre::checkPseudo($this->pseudo)) !== true) {
             $std->msg[] = $res;
         }
         if (($res = Membre::checkEmail($this->email)) !== true) {
             $std->msg[] = $res;
         }
         $captcha = new Captcha();
         if (($res = $captcha->check($this->captcha)) !== true) {
             $std->msg[] = $res;
         }
     }
     if (($res = $this->checkSujet($this->sujet)) !== true) {
         $std->msg[] = $res;
     }
     if (($res = $this->checkMessage($this->message)) !== true) {
         $std->msg[] = $res;
     }
     if (empty($std->msg)) {
         $std->success = true;
     }
     return $std;
 }
Beispiel #3
0
function generate_overview($filecats = '', $offset = '', $subcatID = 0)
{
    global $_language;
    $rubrics = safe_query("SELECT * FROM " . PREFIX . "files_categorys WHERE subcatID = '" . $subcatID . "' ORDER BY name");
    $i = 1;
    $CAPCLASS = new Captcha();
    $CAPCLASS->create_transaction();
    $hash = $CAPCLASS->get_hash();
    while ($ds = mysql_fetch_array($rubrics)) {
        if ($i % 2) {
            $td = 'td1';
        } else {
            $td = 'td2';
        }
        $filecats .= '<tr>
        <td class="' . $td . '">' . $offset . getinput($ds['name']) . '</td>
        <td class="' . $td . '" align="center"><input type="button" onclick="MM_goToURL(\'parent\',\'admincenter.php?site=filecategorys&amp;action=edit&amp;filecatID=' . $ds['filecatID'] . '\');return document.MM_returnValue" value="' . $_language->module['edit'] . '" />
        <input type="button" onclick="MM_confirm(\'' . $_language->module['really_delete'] . '\', \'admincenter.php?site=filecategorys&amp;delete=true&amp;filecatID=' . $ds['filecatID'] . '&amp;captcha_hash=' . $hash . '\')" value="' . $_language->module['delete'] . '" /></td>
    	</tr>';
        $i++;
        if (mysql_num_rows(safe_query("SELECT * FROM " . PREFIX . "files_categorys WHERE subcatID = '" . $ds['filecatID'] . "'"))) {
            $filecats .= generate_overview("", $offset . getinput($ds['name']) . " &raquo; ", $ds['filecatID']);
        }
    }
    return $filecats;
}
Beispiel #4
0
 /**
  * @param $session
  */
 function image($session)
 {
     App::import('Vendor', 'Captcha', array('file' => 'captcha' . DS . 'captcha.php'));
     $captcha = new Captcha();
     $captcha->session_var = $this->sessionName . $session;
     $captcha->CreateImage();
 }
Beispiel #5
0
 function auth()
 {
     if (!valid('janitor_board')) {
         // Admin.php login
         $temp = "" . "<div align='center' vertical-align='middle'>" . ($temp = '<form action="' . PHP_ASELF . '" method="post"><table>' . '<tr><td>Username</td><td><input type="text" name="usernm"  style="width:100%" /></td></tr>' . '<tr><td>Password</td><td><input type="password" name="passwd" style="width:100%" /></td></tr>');
         if (SECURE_LOGIN) {
             if (RECAPTCHA) {
                 $temp .= "<tr><td colspan='2'><script src='//www.google.com/recaptcha/api.js'></script><div class='g-recaptcha' data-sitekey='" . RECAPTCHA_SITEKEY . "'></td></tr>";
             } else {
                 $temp .= "<tr><td><img src='" . CORE_DIR_PUBLIC . "/general/captcha.php' /></td><td><input type='text' name='num' size='20' placeholder='Captcha'></td></tr>";
             }
         }
         $temp .= "<tr><td colspan='2'><input type='submit' value='" . S_MANASUB . "'></td></tr></table>" . "<br></form></div>";
         echo $temp;
         if (isset($_POST['usernm']) && isset($_POST['passwd'])) {
             if (SECURE_LOGIN) {
                 require_once CORE_DIR . '/general/captcha.php';
                 $captcha = new Captcha();
                 if ($captcha->isValid() !== true) {
                     $this->error(S_CAPFAIL);
                 }
             }
             $this->doLogin($_POST['usernm'], $_POST['passwd']);
             echo "<META HTTP-EQUIV=\"refresh\" content=\"0;URL=" . PHP_ASELF_ABS . "\">";
         }
         die("</body></html>");
     }
     return $temp;
 }
 public function captcha()
 {
     $this->load->library('captcha');
     $captcha = new Captcha();
     $this->session->data['captcha'] = $captcha->getCode();
     $captcha->showImage();
 }
		public function captcha(){
			//获取验证码
			$captcha = new Captcha();
			//修改响应头
			header('Content-type:image/png');
			$captcha->generate();
		}
Beispiel #8
0
 /**
  * Genera Img Captcha
  *
  */
 public function captcha()
 {
     Load::lib('captcha/captcha');
     View::select(NULL, NULL);
     $captcha = new Captcha();
     $captcha->run();
 }
Beispiel #9
0
 public function index()
 {
     $c = new Captcha();
     $c->doimg();
     $code = $c->getCode();
     session("myf_code", $code);
 }
 public function captcha()
 {
     $this->load->library("captcha");
     $captcha = new Captcha();
     $captcha->size = 6;
     $captcha->session = "captcha";
     $captcha->display();
 }
 public function generateCaptcha()
 {
     require_once '../core/Captcha.php';
     $cap = new Captcha();
     $src = $cap->draw_captcha();
     $time = $cap->time;
     print $time . '#' . $src;
 }
Beispiel #12
0
 public function checkRegistrationAndActualCountryAfterFailedLogin(Captcha $captcha, User $user, $loginCountry)
 {
     $registrationCountry = $user->getRegistrationCountry();
     if ($registrationCountry != $loginCountry) {
         $captcha->setCaptchaStatus(true);
     }
     return $captcha->getCaptchaStatus();
 }
Beispiel #13
0
function captcha($pattern, $left, $operator, $right)
{
    if ($pattern < 1 or $pattern > 2 or ($operator < 1 or $operator > 3)) {
        return "You shouldn't do this to me :(" . "\n";
    }
    $captcha = new Captcha($pattern, $left, $operator, $right);
    return $captcha->toString();
}
 function buildCaptcha()
 {
     $pattern = $this->randomizer->pattern();
     $left = $this->randomizer->operand();
     $operator = $this->randomizer->operator();
     $right = $this->randomizer->operand();
     $captcha = new Captcha($pattern, $left, $operator, $right);
     return $captcha->toString();
 }
 public function getCaptcha()
 {
     $width = Input::get('w', 100);
     $height = Input::get('h', 25);
     $letters = Input::get('letters', 4);
     $cpa = new Captcha($width, $height, $letters);
     header("Content-Type: image/png");
     return $cpa->createImage();
 }
Beispiel #16
0
 function captcha()
 {
     $this->load->library('captcha');
     $captcha = new Captcha();
     $captcha->size = 4;
     $captcha->chars = '0123456789';
     $captcha->session = "captcha";
     $captcha->display();
 }
 public function execute(&$value, &$error)
 {
     $g = new Captcha(sfContext::getInstance()->getUser()->getAttribute('captcha'));
     if ($g->verify($value)) {
         return true;
     }
     $error = $this->getParameter('error', sfConfig::get('app_captcha_error', 'You should specify valid Turing number'));
     return false;
 }
 function perform()
 {
     // if all data is correct, then we can proceed and use it
     $tf = new Textfilter();
     $this->userName = $tf->filterAllHTML($this->_request->getValue("userName"));
     $this->userPassword = $tf->filterAllHTML($this->_request->getValue("userPassword"));
     $this->confirmPassword = $tf->filterAllHTML($this->_request->getValue("userPasswordCheck"));
     $this->userEmail = $tf->filterAllHTML($this->_request->getValue("userEmail"));
     $this->userFullName = $tf->filterAllHTML($this->_request->getValue("userFullName"));
     $this->captcha = $this->_request->getValue("userAuth");
     // check if there is already a user with the same username and quit if so
     $users = new Users();
     if ($users->userExists($this->userName)) {
         $this->_view = new SummaryUserCreationView();
         //$this->_form->hasRun( true );
         $this->_form->setFieldValidationStatus("userName", false);
         $this->setCommonData(true);
         return false;
     }
     // check if this email account has registered and quit if so, but only if the configuration
     // says that we should only allow one blog per email account
     if ($this->_config->getValue("force_one_blog_per_email_account")) {
         if ($users->emailExists($this->userEmail)) {
             $this->_view = new SummaryUserCreationView();
             //$this->_form->hasRun( true );
             $this->_form->setFieldValidationStatus("userEmail", false);
             $this->setCommonData(true);
             return false;
         }
     }
     // check if the passwords match, and stop processing if so too
     if ($this->userPassword != $this->confirmPassword) {
         $this->_view = new SummaryUserCreationView();
         $this->_view->setErrorMessage($this->_locale->tr("error_passwords_dont_match"));
         $this->_form->setFieldValidationStatus("userPasswordCheck", false);
         $this->setCommonData(true);
         return false;
     }
     // check if the captcha matches
     if ($this->_config->getValue("use_captcha_auth")) {
         include_once PLOG_CLASS_PATH . "class/data/captcha/captcha.class.php";
         $captcha = new Captcha();
         if (!$captcha->validate($this->captcha)) {
             $this->_view = new SummaryUserCreationView();
             $this->_view->setErrorMessage($this->_locale->tr("error_invalid_auth_code"));
             $this->_form->setFieldValidationStatus("userAuth", false);
             $this->setCommonData(true);
             return false;
         }
     }
     // if everything went fine, then proceed
     $this->_view = new doBlogRegistrationView();
     $this->setValues();
     $this->setCommonData();
     return true;
 }
 /**
  * Creates and returns a captcha object from a row
  * @param $row array
  * @return Captcha object
  */
 function &_returnCaptchaFromRow($row)
 {
     $captcha = new Captcha();
     $captcha->setId($row['captcha_id']);
     $captcha->setSessionId($row['session_id']);
     $captcha->setValue($row['value']);
     $captcha->setDateCreated($this->datetimeFromDB($row['date_created']));
     HookRegistry::call('CaptchaDAO::_returnCaptchaFromRow', array(&$captcha, &$row));
     return $captcha;
 }
 public function __construct(Captcha $c)
 {
     $this->captcha = $c;
     // TODO: random lines
     $this->lines = [['x1' => 0, 'y1' => $c->getWidth() / 2, 'x2' => $c->getWidth(), 'y2' => $c->getHeight() / 2, 'color' => '#00ff00', 'width' => 1], ['x1' => 0, 'y1' => 10, 'x2' => $c->getWidth(), 'y2' => $c->getHeight() / 1.3, 'color' => '#cccccc', 'width' => 2], ['x1' => 0, 'y1' => $c->getHeight() / 2, 'x2' => $c->getWidth(), 'y2' => $c->getHeight() / 3, 'color' => '#cccccc', 'width' => 2]];
     $this->fontSize = 12;
     $this->borderColor = '#666666';
     $this->backgroundColor = '#f1f1f1';
     $this->textColor = '#333333';
     $this->text = $c->getGenerateValue();
 }
Beispiel #21
0
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->load->library('captcha');
     $captcha = new Captcha();
     $this->session->data['captcha'] = $captcha->getCode();
     $captcha->showImage();
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
 private function check_captcha($captext, $captime)
 {
     $captext = trim($captext, ' ');
     if ($captext != '') {
         $cap = new Captcha();
         if ($cap->check_captcha($captext, $captime) == 0) {
             return 0;
             //$this->error['captext'] = sprintf ( "%sСимволи введені невірно<br />", $this->error['captext'] );
         } else {
             return 1;
         }
     }
 }
 public function executeShow()
 {
     // retrieve the user, by fetching from the class defined in app.yml (or in the sfGuardUser class)
     $user_class = sfConfig::get('app_sfSimpleBlog_user_class', 'sfGuardUser');
     $this->user = call_user_func(array($user_class . "Peer", "retrieveByPK"), $this->getUser()->getId());
     $this->post = sfSimpleBlogPostPeer::retrieveByStrippedTitleAndDate($this->getRequestParameter('stripped_title'), $this->getDateFromRequest());
     $this->forward404Unless($this->post);
     $this->comments = $this->post->getComments();
     if (sfConfig::get('app_sfSimpleBlog_comment_automoderation', 'first_post') === 'captcha') {
         $g = new Captcha();
         $this->getUser()->setAttribute('captcha', $g->generate());
     }
 }
Beispiel #24
0
function smarty_function_captcha($params, &$smarty)
{
    $length = (int) $params['length'] ? (int) $params['length'] : 4;
    $name = $params['name'] ? $params['name'] : 'captcha';
    $font = realpath($smarty->template_dir) . "/arial.ttf";
    $tempfolder = "P:/home/link.su/www/uploaded_files";
    $c = new Captcha($length);
    $code = $c->GenStr();
    $c->font = $font;
    $salted = md5($code . CAPTCHA_SALT . 'some salt' . $code . CAPTCHA_SALT . 'extra salt');
    $code = $c->Generate("{$tempfolder}/{$salted}.png");
    return "<img src=\"captcha.php?cap={$salted}\"><INPUT TYPE=HIDDEN NAME=\"{$name}\" value=\"{$salted}\">";
}
 public function execute(&$value, &$error)
 {
     $user = sfContext::getInstance()->getUser();
     $g = new Captcha($user->getAttribute('captcha'));
     if ($g->verify($value)) {
         return true;
     }
     // captcha validation failure => we generate another one
     $g = new Captcha();
     $user->setAttribute('captcha', $g->generate());
     $error = $this->getParameter('error');
     return false;
 }
 public function show($id)
 {
     $this->view->title = 'Абітурієнт';
     $captcha = new Captcha();
     $this->view->src = $captcha->draw_captcha();
     $this->view->time = $captcha->time;
     $this->view->meta_k = '<META NAME="Keywords" CONTENT="Абітурієнти,компютерні системи та мережі, інженерія, ТНЕУ, КІТ, computer systems, networks">';
     $this->view->meta_d = '<META NAME="Description" CONTENT="Кафедра КІ, компютерні системи та мережі, computer systems, networks">';
     $this->view->css = array('menu');
     $this->view->js = array('registration', 'guestbook/addEvent');
     //$this->view->data = $this->model->getInfo($id);
     $this->view->render('showAbiturient/show');
 }
Beispiel #27
0
        function testGraphics_Captcha_Captcha() 
        {
			$options["length"] = 6;
			
			$CAPTCHA = new Captcha($options);

			$string = $CAPTCHA->GetPhrase();
			
			$this->assertTrue($string, "CAPTCHA Phrase generated");
			
			$png = $CAPTCHA->GetImage();
			$this->assertTrue($png, "CAPTCHA Image generated");
			
        }
 /**
  * Create a CAPTCHA object.
  * @param $length int The length, in characters, of the CAPTCHA test to create
  * @return object Captcha
  */
 function &createCaptcha($length = 6)
 {
     $captchaDao =& DAORegistry::getDAO('CaptchaDAO');
     $session =& Request::getSession();
     if ($session && $this->isEnabled()) {
         $captcha = new Captcha();
         $captcha->setSessionId($session->getId());
         $captcha->setValue(Validation::generatePassword($length));
         $captchaDao->insertCaptcha($captcha);
     } else {
         $captcha = null;
     }
     return $captcha;
 }
 /**
  * @param  $request WebRequest
  * @return void
  */
 public function loadDataFromRequest($request)
 {
     $this->captcha = Captcha::factory();
     $this->captcha->loadFromRequest($request, $this);
     if (!$this->captcha->exists()) {
         // The captcha doesn't exist; probably because it's already been used and
         // then deleted for security.  Load the field up with a new captcha which
         // will be shown to the user when the validation of said new object fails
         $this->captcha = Captcha::newRandom();
     }
     // This will be useful as the difference between "the captcha doesn't exist" and
     // "you answered the captcha wrongly"
     return $this->captcha->exists();
 }
 public function __construct($width = '120', $height = '40', $characters = '6')
 {
     $code = $this->generateCode($characters);
     // font size will be 75% of the image height
     $font_size = $height * 0.75;
     $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
     // set the colours
     $background_color = imagecolorallocate($image, 255, 255, 255);
     $text_color = imagecolorallocate($image, 228, 130, 64);
     $noise_color = imagecolorallocate($image, 247, 141, 70);
     // generate random dots in background
     for ($i = 0; $i < $width * $height / 3; $i++) {
         imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
     }
     // generate random lines in background
     for ($i = 0; $i < $width * $height / 150; $i++) {
         imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color);
     }
     // create textbox and add text
     $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
     $x = ($width - $textbox[4]) / 2;
     $y = ($height - $textbox[5]) / 2;
     imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function');
     // output captcha image to browser
     header('Content-Type: image/jpeg');
     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     header("Cache-Control: no-cache");
     header("Pragma: no-cache");
     imagejpeg($image);
     imagedestroy($image);
     CoreLoader::load('Captcha');
     $session_id = Session_manager::getSession()->id;
     $table = new Captcha();
     $rows = $table->loadRowsWhere(array('ip' => $_SERVER['REMOTE_ADDR'], 'session_id' => $session_id));
     if (isset($rows[0])) {
         $row = $rows[0];
     } else {
         $row = $table->loadRow();
     }
     $row->created = time();
     $row->ip = $_SERVER['REMOTE_ADDR'];
     $row->session_id = $session_id;
     $row->code = $code;
     $res = $row->save();
     if (is_array($res)) {
         trigger_error(var_export($res, true));
     }
 }