Esempio n. 1
0
 /**
  * Index Action
  *
  */
 public function indexAction()
 {
     $this->tag->setTitle(__('Admin panel'));
     $this->tag->setTitle(__('Admin panel'));
     /**
      * This code will benchmark your server to determine how high of a cost you can
      * afford. You want to set the highest cost that you can without slowing down
      * you server too much. 8-10 is a good baseline, and more is good if your servers
      * are fast enough. The code below aims for ≤ 50 milliseconds stretching time,
      * which is a good baseline for systems handling interactive logins.
      */
     $timeTarget = 0.05;
     // 50 milliseconds
     $costPhp = 8;
     do {
         $costPhp++;
         $start = microtime(true);
         password_hash("test", PASSWORD_BCRYPT, ["cost" => $costPhp]);
         $end = microtime(true);
     } while ($end - $start < $timeTarget);
     //echo "Appropriate Cost Found: " . $cost . "\n";
     $this->view->setVar('costPhp', $costPhp);
     $costPhal = 8;
     do {
         $costPhal++;
         $start = microtime(true);
         $security = new \Phalcon\Security();
         //$security->setDefaultHash($this->config->security->key);
         $security->setWorkFactor($costPhal);
         $security->setDefaultHash(\Phalcon\Security::CRYPT_BLOWFISH_Y);
         $security->hash("test");
         $end = microtime(true);
     } while ($end - $start < $timeTarget);
     $this->view->setVar('costPhal', $costPhal);
 }
Esempio n. 2
0
 public function setSecur()
 {
     $this->set('security', function () {
         $security = new \Phalcon\Security();
         //Устанавливаем фактор хеширования в 12 раундов
         $security->setWorkFactor(12);
         return $security;
     }, true);
 }
Esempio n. 3
0
 public function testComputeHMAC()
 {
     $s = new \Phalcon\Security();
     $k = md5('test', true);
     $keys = array(substr($k, 0, strlen($k) / 2), $k, $k . $k);
     $data = array();
     for ($i = 1; $i < 256; ++$i) {
         $data[] = str_repeat('a', $i);
     }
     foreach ($keys as $key) {
         foreach ($data as $text) {
             $actual = $s->computeHmac($text, $key, 'md5');
             $expected = hash_hmac('md5', $text, $key);
             $this->assertEquals($expected, $actual);
         }
     }
 }
Esempio n. 4
0
 */
$di->set('config', $config);
$di->set('flashSession', function () {
    $flash = new \Phalcon\Flash\Session(array('error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning'));
    return $flash;
});
/*$di->set(
    'dispatcher',
    function () {
        $dispatcher = new MvcDispatcher();
        $dispatcher->setDefaultNamespace('reportingtool\Controllers');
        return $dispatcher;
    }
);*/
$di->set('security', function () {
    $security = new Phalcon\Security();
    //Set the password hashing factor to 12 rounds
    $security->setWorkFactor(12);
    return $security;
}, true);
/**
 * View cache
 */
$di->set('viewCache', function () use($config) {
    $frontCache = new \Phalcon\Cache\Frontend\None();
    return new Phalcon\Cache\Backend\Memory($frontCache);
    if ($config->application->debug) {
    } else {
        //Cache data for one day by default
        $frontCache = new \Phalcon\Cache\Frontend\Output(array("lifetime" => 86400 * 30));
        return new FileCache($frontCache, array("cacheDir" => APP_PATH . "/app/cache/views/", "prefix" => "reportingtool-cache-"));
Esempio n. 5
0
 $di->set('loginimage', function () {
     return new \Silar\Misc\LoginImageManager();
 });
 // Ruta de APP
 $apppath = realpath('../');
 $di->set('appPath', function () use($apppath) {
     $obj = new \stdClass();
     $obj->path = $apppath;
     return $obj;
 });
 $path = new \stdClass();
 $path->path = $config->general->path;
 $path->tmpfolder = $config->general->tmp;
 $di->set('path', $path);
 $di->set('hash', function () {
     $hash = new \Phalcon\Security();
     //Set the password hashing factor to 12 rounds
     $hash->setWorkFactor(12);
     return $hash;
 }, true);
 /*
  * Este objeto contiene los datos de ubicación del banco de imágenes
  */
 $imgbnk = new \stdClass();
 $imgbnk->loginimages = $config->imagebank->loginimages;
 $imgbnk->appimages = $config->imagebank->appimages;
 $imgbnk->userdir = $config->imagebank->userdir;
 $imgbnk->systemsize = $config->imagebank->systemsize;
 $imgbnk->dirname = $config->imagebank->dirname;
 $imgbnk->relativeloginimages = $config->imagebank->relativeloginimages;
 $imgbnk->relativeappimages = $config->imagebank->relativeappimages;
Esempio n. 6
0
 /**
  * Set the security service
  *
  * @return void
  */
 protected function security()
 {
     $config = $this->_config;
     $this->_di->set('security', function () use($config) {
         $security = new \Phalcon\Security();
         $security->setWorkFactor($config->auth->hash_workload);
         $security->setDefaultHash(\Phalcon\Security::CRYPT_BLOWFISH_Y);
         return $security;
     });
 }
Esempio n. 7
0
<?php

use Phalcon\Logger\Adapter\File as Logger;
$di['session'] = function () use($config) {
    $session = new \Phalcon\Session\Adapter\Redis(array('uniqueId' => $config->session->unique_id, 'path' => $config->session->path, 'name' => $config->session->name));
    $session->start();
    return $session;
};
$di['security'] = function () {
    $security = new Phalcon\Security();
    $security->setWorkFactor(13);
    $security->setDefaultHash(Phalcon\Security::CRYPT_BLOWFISH_Y);
    return $security;
};
$di['redis'] = function () use($config) {
    $redis = new \Redis();
    $redis->connect($config->redis->host, $config->redis->port);
    return $redis;
};
$di['url'] = function () use($config, $di) {
    $url = new \Phalcon\Mvc\Url();
    return $url;
};
$di['voltService'] = function ($view, $di) use($config) {
    $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
    if (!is_dir($config->view->cache->dir)) {
        mkdir($config->view->cache->dir);
    }
    $volt->setOptions(array("compiledPath" => $config->view->cache->dir, "compiledExtension" => ".compiled", "compileAlways" => true));
    return $volt;
};
Esempio n. 8
0
 /**
  * Set the security service
  *
  * @package     las
  * @version     1.0
  *
  * @return void
  */
 protected function security()
 {
     $config = $this->_config;
     $this->_di->set('security', function () use($config) {
         $security = new \Phalcon\Security();
         $security->setDefaultHash($config->security->key);
         return $security;
     });
 }
Esempio n. 9
0
 public function validatePassword($tryPassword)
 {
     $security = new \Phalcon\Security();
     return $security->checkHash($tryPassword, $this->password);
 }
Esempio n. 10
0
 /**
  * Hash para validacion y creacion de contraseñas de los usuarios
  * @return DI object
  */
 private function setSecurityHash()
 {
     $this->di->set('hash', function () {
         $hash = new \Phalcon\Security();
         //Set the password hashing factor to 12 rounds
         $hash->setWorkFactor(12);
         return $hash;
     }, true);
 }
Esempio n. 11
0
<?php

use Phalcon\Di\FactoryDefault;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
use Phalcon\Mvc\Model\Metadata\Memory as MetaData;
$di = new FactoryDefault();
/**
 * Add Db Service
 */
$di->set('db', new DbAdapter(['host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname]));
/**
 * If the configuration specify the use of metadata adapter use it or use memory otherwise
 */
$di->set('modelsMetadata', new MetaData());
/**
 * Add models manager
 */
$di->setShared('modelsManager', new Phalcon\Mvc\Model\Manager());
/**
 * Add security
 */
$security = new \Phalcon\Security();
$security->setWorkFactor(12);
$di->setShared('security', $security);
/**
 * Add config
 */
$di->set('config', $config);
Esempio n. 12
0
 /**
  * Encrype Password
  * @author Jack <*****@*****.**>
  * @created_date 2015-11-18
  * @updated_date 2015-11-18
  * @param        string     password before encrypt
  * @return       string     password after encrypt
  */
 public static function encryptPass($password)
 {
     $security = new \Phalcon\Security();
     $key = 'secret';
     return $security->hash(crypt($password, $key));
 }