function checkCode($checkarray, $captchatype = 'myCaptcha') { if ($captchatype == 'myCaptcha') { // First, delete old captchas $expiration = time() - 3600; // Two hour limit $db =& JFactory::getDBO(); $db->setQuery("DELETE FROM #__cb_mycaptcha WHERE captcha_time < " . $expiration); $db->query(); // Then see if a captcha exists: $sql = "SELECT COUNT(*) AS count " . "\n FROM #__cb_mycaptcha " . "\n WHERE word = '{$checkarray['word']}' AND ip_address = '{$checkarray['ip']}' AND captcha_time > {$expiration}"; $query = $db->setQuery($sql); if ($db->loadResult()) { return true; } else { return false; } } if ($captchatype == 'reCaptcha') { require_once 'recaptcha' . DS . 'recaptchalib.php'; $res = recaptcha_check_answer($checkarray['privatekey'], CbmycaptchaModel::GetUserIp(), $checkarray["rec_ch_field"], $checkarray["rec_res_field"]); if (!$res->is_valid) { return false; } else { return true; } } }
function onBeforeUsernameReminder($ui, &$subject, &$message) { global $_POST, $_PLUGINS; $params = $this->params; $captchatype = $params->get('captchatype', 'myCaptcha'); if ($captchatype == 'myCaptcha') { $checkarray = array('word' => $_POST['cb_mycaptcha'], 'ip' => CbmycaptchaModel::GetUserIp()); } else { $privatekey = $params->get('privatekey', ''); $checkarray = array('privatekey' => $privatekey, 'rec_ch_field' => $_POST["recaptcha_challenge_field"], 'rec_res_field' => $_POST["recaptcha_response_field"]); } $res = CbmycaptchaModel::checkCode($checkarray, $captchatype); if (!$res) { $_PLUGINS->raiseError(0); $_PLUGINS->_setErrorMSG(_UE_CAPTCHA_NOT_VALID); } return true; }