예제 #1
2
 public function build($name, array $options = [])
 {
     $width = isset($options['width']) ? $options['width'] : 150;
     $height = isset($options['height']) ? $options['height'] : 40;
     $font = isset($options['font']) ? $options['font'] : null;
     $phraseBuilder = new PhraseBuilder();
     if (isset($options['captcha'])) {
         $captcha = $options['captcha'];
     } elseif (isset($options['length'])) {
         $captcha = $phraseBuilder->build($options['length']);
     } else {
         $captcha = null;
     }
     $captchaBuilder = new CaptchaBuilder($captcha, $phraseBuilder);
     if (isset($options['text_color'])) {
         $captchaBuilder->setBackgroundColor($options['text_color'][0], $options['text_color'][1], $options['text_color'][2]);
     }
     if (isset($options['background_color'])) {
         $captchaBuilder->setBackgroundColor($options['background_color'][0], $options['background_color'][1], $options['background_color'][2]);
     }
     if (isset($options['background_images'])) {
         $captchaBuilder->setBackgroundColor($options['background_image']);
     }
     if (isset($options['ignore_effect'])) {
         $captchaBuilder->setIgnoreAllEffects($options['ignore_effect']);
     }
     $captchaBuilder->build($width, $height, $font);
     $captcha = $captchaBuilder->getPhrase();
     session(['image_captcha.' . $name => $captcha]);
     $this->captchaBuilder = $captchaBuilder;
     return $this;
 }
예제 #2
1
 private function newCaptcha()
 {
     $builder = new CaptchaBuilder();
     $builder->build();
     Session::set(['phrase' => $builder->getPhrase()]);
     return $builder->inline();
 }
예제 #3
0
 protected function generate($generate = false)
 {
     if (!empty($this->data) && $generate === false) {
         return $this->data;
     }
     $this->provider->build($this->width, $this->height);
     $this->code = $this->provider->getPhrase();
     return $this->data = ['mimeType' => 'image/jpeg', 'image' => $this->provider->get($this->quality)];
 }
예제 #4
0
 /**
  * @return CaptchaBuilder
  */
 public function generateCaptcha()
 {
     $ip = Request::get()->getRequest()->ip;
     $builder = new CaptchaBuilder();
     $builder->build();
     $key = md5($builder->getPhrase() . $ip);
     getCache()->set($key, $builder->getPhrase(), $this->ttl);
     return $builder;
 }
예제 #5
0
 /**
  * Display captcha image
  *
  * @access public
  */
 public function image()
 {
     $this->response->withContentType('image/jpeg')->send();
     $builder = new CaptchaBuilder();
     $builder->build();
     $this->sessionStorage->captcha = $builder->getPhrase();
     $builder->output();
 }
예제 #6
0
 /**
  * Display captcha image
  *
  * @access public
  */
 public function captcha()
 {
     $this->response->contentType('image/jpeg');
     $builder = new CaptchaBuilder();
     $builder->build();
     $this->session['captcha'] = $builder->getPhrase();
     $builder->output();
 }
예제 #7
0
 public function index()
 {
     $builder = new CaptchaBuilder();
     $builder->build($width = 100, $height = 34, $font = null);
     Session::put('phrase', $builder->getPhrase());
     header('Cache-Control: no-cache, must-revalidate');
     header('Content-Type: image/jpeg');
     $builder->output();
 }
예제 #8
0
 public function login()
 {
     Session_start();
     $builder = new CaptchaBuilder();
     $builder->build();
     $phrase = $builder->getPhrase();
     $_SESSION['phrase'] = $phrase;
     return View::make('login')->with(array('captcha' => $builder, 'links' => $this->link()));
 }
예제 #9
0
 /**
  * @return CaptchaBuilder
  */
 private function getCaptchaBuilder()
 {
     if (!$this->captchaBuilder) {
         $this->captchaBuilder = new CaptchaBuilder();
         $this->captchaBuilder->build(200, 80);
         $this->sessionSection->captcha = $this->captchaBuilder->getPhrase();
     }
     return $this->captchaBuilder;
 }
예제 #10
0
 public function index()
 {
     $builder = new CaptchaBuilder();
     $builder->build(150, 32);
     //session(['captcha'=>$builder->getPhrase()]);
     \Session::set('captcha', $builder->getPhrase());
     //存储验证码
     return response($builder->output())->header('Content-type', 'image/jpeg');
 }
예제 #11
0
 public function display()
 {
     $builder = new CaptchaBuilder();
     $builder->build();
     $this->Session->write('captcha', $builder->getPhrase());
     $this->response->header('Content-type', 'image/jpeg');
     $this->response->body($builder->get());
     $this->response->send();
     return $this->response;
 }
예제 #12
0
 public static function create($phrase = null)
 {
     $builder = new CaptchaBuilder();
     if ($phrase) {
         $builder->setPhrase($phrase);
     }
     $builder->build();
     Session::put(static::$config['session'], Hash::make(Str::lower($builder->getPhrase())));
     return Response::make($builder->get())->header('Content-type', 'image/jpeg');
 }
예제 #13
0
 public function captcha($tmp)
 {
     ob_clean();
     //生成验证码图片的Builder对象,配置相应属性
     $builder = new CaptchaBuilder();
     $builder->build(100, 25);
     \Session::set('phrase', $builder->getPhrase());
     //存储验证码
     return response($builder->output())->header('Content-type', 'image/jpeg');
 }
예제 #14
0
 /**
  * Generates the captcha, "returns" a real image, this is why there is header('Content-type: image/jpeg')
  * Note: This is a very special method, as this is echoes out binary data.
  */
 public static function generateAndShowCaptcha()
 {
     // create a captcha with the CaptchaBuilder lib (loaded via Composer)
     $captcha = new CaptchaBuilder();
     $captcha->build(Config::get('CAPTCHA_WIDTH'), Config::get('CAPTCHA_HEIGHT'));
     // write the captcha character into session
     Session::set('captcha', $captcha->getPhrase());
     // render an image showing the characters (=the captcha)
     header('Content-type: image/jpeg');
     $captcha->output();
 }
예제 #15
0
파일: Utilities.php 프로젝트: enpowi/enpowi
 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');
 }
예제 #16
0
 public function captcha()
 {
     session_start();
     $builder = new CaptchaBuilder();
     $builder->build();
     $_SESSION['phrase'] = $builder->getPhrase();
     header("Cache-Control: no-cache, must-revalidate");
     header('Content-Type: image/jpeg');
     // return $_SESSION['phrase'];
     $builder->output();
     exit;
 }
예제 #17
0
파일: Captcha.php 프로젝트: phpffcms/ffcms
 /**
  * Build gregwar captcha image
  */
 public function actionGregwar()
 {
     // set header. Class response->header->set is not working here (content output directly before)
     header('Content-type: image/jpeg');
     $builder = new CaptchaBuilder();
     $builder->build(200, 60);
     // build and set width/height
     // set captcha value to session
     App::$Session->set('captcha', $builder->getPhrase());
     // set header and display JPEG
     $this->response->headers->set('Content-type', 'image/jpeg');
     $builder->output();
 }
예제 #18
0
 /**
  * 输出验证码
  */
 public function captcha()
 {
     $builder = new CaptchaBuilder();
     $builder->build();
     $phrase = $builder->getPhrase();
     Crypt::setKey(Config::get('app.cookie_key'));
     $phrase_new = Crypt::encrypt($phrase);
     Session::flash('__captcha', $phrase_new);
     header("Cache-Control: no-cache, must-revalidate");
     header('Content-Type: image/jpeg');
     $builder->output();
     exit;
 }
예제 #19
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function captcha($tmp)
 {
     //生成验证码图片的Builder对象,配置相应属性
     $builder = new CaptchaBuilder();
     //可以设置图片宽高及字体
     $builder->build($width = 140, $height = 50, $font = null);
     //获取验证码的内容
     $phrase = $builder->getPhrase();
     //把内容存入session
     Session::put('milkcaptcha', $phrase);
     //生成图片
     header("Cache-Control: no-cache, must-revalidate");
     header('Content-Type: image/jpeg');
     $builder->output();
 }
예제 #20
0
 /**
  * Generate a captcha as a jpeg image, and return its filename
  * (relative to the WEB directory).
  * If a captcha already exists in session, return its filename directly.
  */
 public function getFilename()
 {
     $imageFileHandler = new ImageFileHandler($this->imageFolder, $this->webPath, 20, 60);
     // Randomly execute garbage collection
     $imageFileHandler->collectGarbage();
     // If a captcha already exists in session => return it directly
     if (($captcha = $this->session->get($this->sessionKey)) && ($filename = @$captcha['filename']) && file_exists($this->webPath . '/' . $filename)) {
         touch($this->webPath . '/' . $filename);
         // update modification date
         return $filename;
     }
     // Generate a captcha
     $builder = new CaptchaBuilder();
     $content = $builder->build(225, 60)->getGd();
     // Save it in session
     $this->session->set($this->sessionKey, ['phrase' => $builder->getPhrase(), 'filename' => $filename = $imageFileHandler->saveAsFile($content)]);
     return $filename;
 }
 /**
  * 生成验证码.
  *
  * @Route("captcha", name="site_common_captcha")
  */
 public function captchaAction()
 {
     $width = intval($this->getRequestItem('width', 150));
     // 验证码图片的宽度
     $height = intval($this->getRequestItem('height', 50));
     // 验证码图片的高度
     $length = 5;
     // 验证码字符的长度
     $no_effect = true;
     // 是否忽略验证图片上的干扰线条
     $pharse = new PhraseBuilder();
     $captcha = new CaptchaBuilder($pharse->build($length));
     $image = $captcha->setIgnoreAllEffects($no_effect)->build($width, $height)->get();
     $this->setSessionItem('captcha', $captcha->getPhrase());
     $res = new Response($image);
     $res->headers->set('content-type', 'image/jpeg');
     return $res;
 }
 public function captchaAction(Request $request)
 {
     $imgBuilder = new CaptchaBuilder();
     $imgBuilder->build($width = 150, $height = 32, $font = null);
     $request->getSession()->set('captcha_code', strtolower($imgBuilder->getPhrase()));
     ob_start();
     $imgBuilder->output();
     $str = ob_get_clean();
     $imgBuilder = null;
     $headers = array('Content-type' => 'image/jpeg', 'Content-Disposition' => 'inline; filename="' . "reg_captcha.jpg" . '"');
     return new Response($str, 200, $headers);
 }
예제 #23
0
<?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>
예제 #24
0
                    $_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));
}
예제 #25
0
 /**
  * 生成登录页面的图形验证码
  *
  * @author young
  * @name 生成登录页面的图形验证码
  * @version 2013.11.07 young
  * @return \Zend\Stdlib\ResponseInterface
  */
 public function captchaAction()
 {
     $builder = new CaptchaBuilder();
     $builder->setBackgroundColor(255, 255, 255);
     $builder->setTextColor(255, 0, 255);
     $builder->setPhrase(rand(100000, 999999));
     $_SESSION['phrase'] = $builder->getPhrase();
     $builder->build(150, 40);
     header('Content-type: image/jpeg');
     $this->response->setContent($builder->output(80));
     return $this->response;
 }
예제 #26
0
 /**
  * Generates the captcha, "returns" a real image,
  * this is why there is header('Content-type: image/jpeg')
  * Note: This is a very special method, as this is echoes out binary data.
  * Eventually this is something to refactor
  */
 public function generateCaptcha()
 {
     // create a captcha with the CaptchaBuilder lib
     $builder = new CaptchaBuilder();
     $builder->build();
     // write the captcha character into session
     $_SESSION['captcha'] = $builder->getPhrase();
     // render an image showing the characters (=the captcha)
     header('Content-type: image/jpeg');
     $builder->output();
 }
예제 #27
0
 /**
  * 获取验证码
  * @param CaptchaBuilder $builder
  * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  */
 public function getCaptcha(CaptchaBuilder $builder)
 {
     $builder->build(100);
     Session::put('captcha', $builder->getPhrase());
     return response($builder->output(), 200, ['Content-type', 'image/jpeg']);
 }
예제 #28
0
 public function captcha()
 {
     $builder = new CaptchaBuilder();
     $builder->build(300, 122);
     Session::flash('phrase', $builder->getPhrase());
     //存储验证码
     return response($builder->output())->header('Content-type', 'image/jpeg');
 }
예제 #29
0
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());
}
예제 #30
0
 /**
  * 登录验证码生成
  *
  * @return \Zend\Stdlib\ResponseInterface
  */
 public function captchaAction()
 {
     $builder = new CaptchaBuilder();
     // $builder->setBackgroundColor($r, $g, $b);
     // $builder->build($width = 150, $height = 40);
     $builder->build(150, 40);
     $_SESSION['phrase'] = $builder->getPhrase();
     // $builder->output($quality = 80);
     header('Content-type: image/jpeg');
     $this->response->setContent($builder->output(80));
     return $this->response;
 }