private function newCaptcha() { $builder = new CaptchaBuilder(); $builder->build(); Session::set(['phrase' => $builder->getPhrase()]); return $builder->inline(); }
public function actionIndex() { $codeId = (string) new \MongoId(); $code = StringUtil::rndString(4, 1); $builder = new CaptchaBuilder($code); $builder->build(160, 50); $cache = Yii::$app->cache; $duration = Yii::$app->params['img_captcha_availab_time']; $cache->set($codeId, $code, $duration); return ['message' => 'OK', 'data' => $builder->inline(), 'codeId' => $codeId]; }
public static function captcha($isNew = false) { $app = Enpowi\App::get(); $segment = $app->session->getSegment(__CLASS__); if (!isset($segment->phrase) || $isNew) { $builder = new CaptchaBuilder(); $builder->build(); $segment->set('phrase', $builder->getPhrase()); $segment->set('image', $builder->inline()); } return $segment->get('image'); }
include_once 'captcha/PhraseBuilderInterface.php'; include_once 'captcha/CaptchaBuilder.php'; include_once 'captcha/PhraseBuilder.php'; use Gregwar\Captcha\CaptchaBuilder; try { $user = new \User\User(); switch ($_GET["page"]) { case "login": if ($user->is_logged()) { $usr = $user->get_user(); echo "id:" . $user["id"] . "<br>"; echo "Last visited:" . date("d-M-Y", $user["last_visited"]); } else { echo ' <form name="login_form" method="POST" action="post.php">'; echo 'E-mail: <input type="text" name="email"><br>'; echo 'Password: <input type="password" name="password"><br>'; if (isset($_SESSION["incorect_logins"]) && $_SESSION["incorect_logins"] >= 2) { $builder = new CaptchaBuilder(); $builder->build(); echo '<img src="' . $builder->inline() . '" /><br>'; echo 'Captcha: <input type="text" name="captcha"><br>'; $_SESSION["captcha_answer"] = $builder->getPhrase(); } echo '<input type="submit" name="submit" value="Login">'; echo '</form>'; break; } } } catch (Exception $e) { file_put_contents("log.txt", $e->getMessage()); }
<?php session_start(); require "vendor/autoload.php"; use Gregwar\Captcha\CaptchaBuilder; $builder = new CaptchaBuilder(); $builder->build(); //$builder->save('out.jpg'); if (isset($_POST['entree'])) { if ($_SESSION['phrase'] == $_POST['entree']) { echo "ok"; } else { echo "**pas ok**"; } } $_SESSION['phrase'] = $builder->getPhrase(); ?> <img src="<?php echo $builder->inline(); ?> " /> <form action"essai.php" method="post"> <input name="entree" type="text"> <input name="valider" type="submit"> </form>
$_SESSION['dialog']['danger'][] = _('Fail to recover password'); } } else { $_SESSION['dialog']['danger'][] = _('Recover password disabled'); } } else { $_SESSION['dialog']['danger'][] = _('Please type the displayed captcha phrase correctly'); } } if ($ok) { header("Location: " . _u($core_config['http_path']['base'])); } else { header("Location: " . _u('index.php?app=main&inc=core_auth&route=forgot')); } exit; } else { $enable_logo = FALSE; $show_web_title = TRUE; if ($core_config['main']['enable_logo'] && $core_config['main']['logo_url']) { $enable_logo = TRUE; if ($core_config['main']['logo_replace_title']) { $show_web_title = FALSE; } } // captcha $captcha = new CaptchaBuilder(); $captcha->build(); $_SESSION['tmp']['captcha'] = $captcha->getPhrase(); $tpl = array('name' => 'auth_forgot', 'vars' => array('HTTP_PATH_BASE' => $core_config['http_path']['base'], 'WEB_TITLE' => $core_config['main']['web_title'], 'DIALOG_DISPLAY' => _dialog(), 'URL_ACTION' => _u('index.php?app=main&inc=core_auth&route=forgot&op=forgot'), 'URL_REGISTER' => _u('index.php?app=main&inc=core_auth&route=register'), 'URL_LOGIN' => _u('index.php?app=main&inc=core_auth&route=login'), 'CAPTCHA_IMAGE' => $captcha->inline(), 'HINT_CAPTCHA' => _hint(_('Read and type the captcha phrase on verify captcha field. If you cannot read them please contact administrator.')), 'Username' => _('Username'), 'Email' => _('Email'), 'Recover password' => _('Recover password'), 'Login' => _('Login'), 'Submit' => _('Submit'), 'Register an account' => _('Register an account'), 'Verify captcha' => _('Verify captcha'), 'logo_url' => $core_config['main']['logo_url']), 'ifs' => array('enable_register' => $core_config['main']['enable_register'], 'enable_logo' => $enable_logo, 'show_web_title' => $show_web_title)); _p(tpl_apply($tpl)); }
/** * Gets the HTML inline base64 * * @access public * @param string $quality Image quality * @return void */ public function inline($quality = 90) { return $this->builder->inline($quality); }