Ejemplo n.º 1
0
 /**
  * Load connection parameters from config file.
  *
  * @access  private
  * @param   string  $connection  Connection group name
  */
 private function setBuilder($width = 150, $height = 40, $font = null)
 {
     if ($this->session->has($this->secret . '::phrase') && $this->isAlive()) {
         // Get phrase saved in session
         $sessionPhrase = $this->session->get($this->secret . '::phrase');
         // Decrypt phrase
         $phrase = $this->encrypter->decrypt($sessionPhrase);
         // Captcha builder
         $this->builder = new CaptchaBuilder($phrase);
         $this->builder->setDistortion(false);
         $this->builder->setMaxBehindLines(0);
         $this->builder->setMaxFrontLines(0);
         $this->builder->setIgnoreAllEffects(false);
         $this->builder->setBackgroundColor(241, 241, 241);
         $this->builder->build($width, $height, $font);
     } else {
         // Captcha builder
         $this->builder = new CaptchaBuilder();
         $this->builder->setDistortion(false);
         $this->builder->setMaxBehindLines(0);
         $this->builder->setMaxFrontLines(0);
         $this->builder->setIgnoreAllEffects(false);
         $this->builder->setBackgroundColor(241, 241, 241);
         $this->builder->build($width, $height, $font);
         // Set last generated phrase
         $this->session->put($this->secret . '::phrase', $this->encrypter->encrypt($this->builder->getPhrase()));
         // Set last modified time
         $this->session->put($this->secret . '::lastModified', time());
     }
 }
Ejemplo n.º 2
0
 /**
  * Constructor.
  *
  * @access  public
  * @param   Config         $config   Config instance
  * @param   Session        $session  Session instance
  * @param   CryptoManager  $crypto   Crypto Manager
  */
 public function __construct(Config $config, Session $session, CryptoManager $crypto)
 {
     // Config Instance
     $this->config = $config;
     // Session Instance
     $this->session = $session;
     // CryptoManager instance
     $this->encrypter = $crypto->instance();
     // Session Instance
     $this->setSecret($this->config->get('makocaptcha::config.secret'));
     // Builder options
     $width = $this->config->get('makocaptcha::config.width');
     $height = $this->config->get('makocaptcha::config.height');
     $font = $this->config->get('makocaptcha::config.font');
     // Set captcha builder
     $this->setBuilder($width, $height, $font);
 }