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; }
private function newCaptcha() { $builder = new CaptchaBuilder(); $builder->build(); Session::set(['phrase' => $builder->getPhrase()]); return $builder->inline(); }
/** * @param array $options * * @return string */ public function generate(array &$options) { $this->builder->setDistortion($options['distortion']); $this->builder->setMaxFrontLines($options['max_front_lines']); $this->builder->setMaxBehindLines($options['max_behind_lines']); if (isset($options['text_color']) && $options['text_color']) { if (count($options['text_color']) !== 3) { throw new \RuntimeException('text_color should be an array of r, g and b'); } $color = $options['text_color']; $this->builder->setTextColor($color[0], $color[1], $color[2]); } if (isset($options['background_color']) && $options['background_color']) { if (count($options['background_color']) !== 3) { throw new \RuntimeException('background_color should be an array of r, g and b'); } $color = $options['background_color']; $this->builder->setBackgroundColor($color[0], $color[1], $color[2]); } $this->builder->setInterpolation($options['interpolation']); $fingerprint = isset($options['fingerprint']) ? $options['fingerprint'] : null; $content = $this->builder->build($options['width'], $options['height'], $options['font'], $fingerprint)->getGd(); if ($options['keep_value']) { $options['fingerprint'] = $this->builder->getFingerprint(); } if (!$options['as_file']) { ob_start(); imagejpeg($content, null, $options['quality']); return ob_get_clean(); } return $this->imageFileHandler->saveAsFile($content); }
protected function renderImage($code) { $builder = new CaptchaBuilder($code); $builder->setBackgroundColor(255, 255, 255); $builder->build(150, 40, $this->fontFile); return $builder->get(); }
/** * 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(); }
/** * 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(); }
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'); }
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(); }
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())); }
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)]; }
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; }
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'); }
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'); }
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 function captcha($request, $response, $args) { $id = $args['id']; $builder = new CaptchaBuilder(); $builder->build(); //$builder->getPhrase(); $newResponse = $response->withHeader('Content-type', ' image/jpeg'); //->getBody()->write($builder->output()); $newResponse->getBody()->write($builder->output()); return $newResponse; }
/** * 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(); }
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'); }
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; }
/** * 输出验证码 */ 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; }
/** * 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(); }
public function captcha(Model $Model, $check) { $value = array_values($check); $value = $value[0]; $field = key($check); if (CakeSession::check('captcha')) { $builder = new CaptchaBuilder(); $builder->setPhrase(CakeSession::read('captcha')); if ($builder->testPhrase($value)) { return true; } } return false; }
/** * 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(); }
/** * Validate captcha * * @access protected * @param array $values Form values * @return boolean */ protected function validateCaptcha(array $values) { $errors = array(); if (!isset($this->sessionStorage->captcha)) { $result = false; } else { $builder = new CaptchaBuilder(); $builder->setPhrase($this->sessionStorage->captcha); $result = $builder->testPhrase(isset($values['captcha']) ? $values['captcha'] : ''); if (!$result) { $errors['captcha'] = array(t('Invalid captcha')); } } return array($result, $errors); }
/** * Returns a singleton instance of the CaptchaBuilder * * @return \Gregwar\Captcha\CaptchaBuilder */ protected function getCatpchaBuilder($reset = false) { static $captchaBuilder = null; if ($captchaBuilder === null || $reset === true) { $captchaBuilder = \Gregwar\Captcha\CaptchaBuilder::create(); } return $captchaBuilder; }
/** * @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; }
/** * Publish CAPTCHA image * * @author kuma */ public function captchaAction() { $builder = new CaptchaBuilder(); $builder->build(); $_SESSION['phrase'] = $builder->getPhrase(); header('Content-type: image/jpeg'); $builder->output(); $this->view->disable(); }
/** * 生成验证码. * * @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; }
/** * Test if a given phrase is valid (ie: same as in session). * If yes, return true. * If not, revoke the captcha and return false. */ public function isValid($phrase) { if (!is_string($phrase)) { return false; } if (!$this->session->has($this->sessionKey)) { return false; } $captcha = $this->session->get($this->sessionKey); if (!isset($captcha['phrase'])) { return false; } $builder = new CaptchaBuilder($captcha['phrase']); if (!$builder->testPhrase($phrase)) { $this->revoke(); return false; } return true; }
/** * Validate input phrase * * @access public * @param array $userInput User input phrase * @return string */ public function validate($userInput) { // Validate time if (!$this->isAlive()) { // Regenerate builder $this->regenerate(); return false; } // Validate using builder return $this->builder->testPhrase($userInput); }
/** * @param string $phrase * @return bool */ public function verifyCaptcha($phrase) { if ($phrase) { $ip = Request::get()->getRequest()->ip; $key = md5($phrase . $ip); $v = getCache()->get($key); $b = CaptchaBuilder::create($v); if ($b->testPhrase($phrase)) { return true; } } return false; }