validate() public static method

Validate captcha.
public static validate ( mixed $value = null ) : boolean
$value mixed
return boolean validity of captcha submission
コード例 #1
0
 /**
  * Validates the captcha.
  */
 protected function validateCaptcha()
 {
     if ($this->useCaptcha) {
         $this->captcha = new Captcha($this->captchaID);
         $this->captcha->validate($this->captchaString);
         $this->useCaptcha = false;
     }
 }
コード例 #2
0
 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;
 }
コード例 #3
0
 /**
  * Validates the captcha.
  */
 protected function validateCaptcha()
 {
     if (REGISTER_USE_CAPTCHA && !WCF::getSession()->getVar('captchaDone')) {
         $this->captcha = new Captcha($this->captchaID);
         try {
             $this->captcha->validate($this->captchaString);
         } catch (UserInputException $e) {
             $this->errorType[$e->getField()] = $e->getType();
         }
     }
 }
コード例 #4
0
        public function save()
	{
	    $form = Form::load('logbook.views.AddBlogComment');
            $capval = Captcha::validate();

	    if($form->validate()&&$capval)
	    {
	        Application::alterParam('comment_content',strip_tags(Application::param('comment_content')));
	        $item = new Comment();
		$item->parse();
                $item->set('comment_date',date('Y-m-d H:M:S'));
                $item->setSafe('author_id',Logbook::current()->authorId());
		$item->save();

                Application::setParam('author_id',Application::param('author_id'));
		Application::setParam('entry_id',Application::param('entry_id'));
		$this->redirectOnSave();
	    }
	}
コード例 #5
0
ファイル: Valid.php プロジェクト: steffomix/isim-beo
 /**
  * Check Captcha Code
  * Usage: ->rule(Captcha::CAPTCHA_ID, 'captcha', array(':value'))
  * @param type $value
  */
 public static function captcha($value)
 {
     return Captcha::validate($value);
 }
コード例 #6
0
ファイル: class.usermodel.php プロジェクト: vanilla/vanilla
 /**
  * To be used for basic registration, and captcha registration.
  *
  * @param array $FormPostValues
  * @param bool $CheckCaptcha
  * @param array $Options
  * @return bool|int|string
  * @throws Exception
  */
 public function insertForBasic($FormPostValues, $CheckCaptcha = true, $Options = [])
 {
     $RoleIDs = RoleModel::getDefaultRoles(RoleModel::TYPE_MEMBER);
     if (!is_array($RoleIDs) || count($RoleIDs) == 0) {
         throw new Exception(t('The default role has not been configured.'), 400);
     }
     if (val('SaveRoles', $Options)) {
         $RoleIDs = val('RoleID', $FormPostValues);
     }
     $UserID = false;
     // Define the primary key in this model's table.
     $this->defineSchema();
     // Add & apply any extra validation rules.
     if (val('ValidateEmail', $Options, true)) {
         $this->Validation->applyRule('Email', 'Email');
     }
     // TODO: DO I NEED THIS?!
     // Make sure that the checkbox val for email is saved as the appropriate enum
     if (array_key_exists('ShowEmail', $FormPostValues)) {
         $FormPostValues['ShowEmail'] = forceBool($FormPostValues['ShowEmail'], '0', '1', '0');
     }
     if (array_key_exists('Banned', $FormPostValues)) {
         $FormPostValues['Banned'] = forceBool($FormPostValues['Banned'], '0', '1', '0');
     }
     $this->addInsertFields($FormPostValues);
     if ($this->validate($FormPostValues, true) === true) {
         $Fields = $this->Validation->validationFields();
         // All fields on the form that need to be validated (including non-schema field rules defined above)
         $Username = val('Name', $Fields);
         $Email = val('Email', $Fields);
         $Fields = $this->Validation->schemaValidationFields();
         // Only fields that are present in the schema
         $Fields['Roles'] = $RoleIDs;
         unset($Fields[$this->PrimaryKey]);
         // If in Captcha registration mode, check the captcha value.
         if ($CheckCaptcha && Captcha::enabled()) {
             $captchaIsValid = Captcha::validate();
             if ($captchaIsValid !== true) {
                 $this->Validation->addValidationResult('Garden.Registration.CaptchaPublicKey', 'The captcha was not completed correctly. Please try again.');
                 return false;
             }
         }
         if (!$this->validateUniqueFields($Username, $Email)) {
             return false;
         }
         // Check for spam.
         if (val('ValidateSpam', $Options, true)) {
             $ValidateSpam = $this->validateSpamRegistration($FormPostValues);
             if ($ValidateSpam !== true) {
                 return $ValidateSpam;
             }
         }
         // Define the other required fields:
         $Fields['Email'] = $Email;
         // And insert the new user
         $UserID = $this->insertInternal($Fields, $Options);
         if ($UserID > 0 && !val('NoActivity', $Options)) {
             $ActivityModel = new ActivityModel();
             $ActivityModel->save(['ActivityUserID' => $UserID, 'ActivityType' => 'Registration', 'HeadlineFormat' => t('HeadlineFormat.Registration', '{ActivityUserID,You} joined.'), 'Story' => t('Welcome Aboard!')], false, ['GroupBy' => 'ActivityTypeID']);
         }
     }
     return $UserID;
 }
コード例 #7
0
ファイル: validation.php プロジェクト: hieuvo/captcha
<?php

Validator::extend('captcha', function ($attribute, $value, $parameters) {
    return Captcha::validate($value);
});
コード例 #8
0
ファイル: index.php プロジェクト: sachsy/snippets
// THIS PAGE IS AN EXAMPLE OF THE CAPTCHA IMPLEMENTATION
// YOU MIGHT HAVE TO PLAY AROUND WITH IT FOR A BIT TO MEET YOUR NEEDS
session_start();
require "Captcha.php";
$captcha = new Captcha();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Captcha example</title>
</head>
<body>
<?php 
if (isset($_POST['captcha'])) {
    if ($captcha->validate($_POST['captcha'])) {
        echo '<div style="color: green;">Right captcha entered!</div>';
    } else {
        echo '<div style="color: red;">Wrong captcha entered, please try again.</div>';
    }
}
?>
<br />
<img alt="Captcha" src="captcha-image.php" />
<form action="" method="post" name="captcha">
	<label for="captcha">For security please enter the above captcha</label>
	<br />
	<input name="captcha" id="captcha" type="text" />
	<input name="verify" id="verify" type="submit" value="Verify" />
</form>
</body>
コード例 #9
0
ファイル: functions.validation.php プロジェクト: R-J/vanilla
 /**
  * Validate the request captcha.
  *
  * @param null $value Not used.
  * @return bool Returns true if the captcha is valid or an error message otherwise.
  */
 function validateCaptcha($value = null)
 {
     return Captcha::validate($value);
 }
コード例 #10
0
ファイル: register.php プロジェクト: shylux/TheLegendOfROOT
<?php

if (require_params("username", "email", "password") && Captcha::validate($_POST)) {
    $user = User::create($_REQUEST["username"], $_REQUEST["email"], $_REQUEST["password"]);
    if ($user) {
        $_SESSION["user"] = $user;
        ?>
<script type="text/javascript">window.location="/game";</script><?php 
    }
}
$captcha = new Captcha();
$captcha->generateCaptcha();
?>

<h2>Register</h2>

<form id="register" method="POST">
  <table>
  <tr>
	<td><label for="username">Username</label></td>
	<td><input id="username" name="username" type="text" placeholder="Username" /></td>
  </tr>
  <tr>
	<td><label for="email">Email</label></td>
	<td><input id="email" name="email" type="email" placeholder="Email" /></td>
  </tr>
  <tr>
	<td><label for="password">Password</label></td>
	<td><input id="password" name="password" type="password" placeholder="Password" /></td>
  </tr>
  <tr>
コード例 #11
0
											</table>
							
									</td>
								</tr>
							</table>                                                              		
						</td>
					</tr>
				</table><!-- End 4 Columns -->
							
			</td>
		</tr>
	</table> <!-- End Wrapper -->
	
	</body>
	</html>';
$ans = $_REQUEST['anti'];
require_once plugin_dir_path(__FILE__) . 'class/captcha.class.php';
$c = new Captcha();
$result = $c->validate($ans);
if ($result) {
    add_filter("wp_mail_content_type", "set_html_content_type");
    $headers = "From: Helios Jobs <{$Email}>" . "\r\n";
    wp_mail(get_option('helios_admin_email'), 'Job Application from Helios HR', $Message, $headers, $filess);
    echo "yes";
} else {
    echo "no";
}
function set_html_content_type()
{
    return 'text/html';
}