/** * 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); }
<?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; };
/** * 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; }); }
/** * 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; }); }