public function testNeedsRehashing()
 {
     $boxPassword = new Box_Password();
     $password = '******';
     $hash = $boxPassword->hashIt($password);
     $this->assertInternalType('string', $hash);
     $this->assertNotEmpty($hash);
     $newOptions = array('cost' => 15);
     $boxPassword->setOptions($newOptions);
     $needRehashing = $boxPassword->needsRehash($hash);
     $this->assertInternalType('bool', $needRehashing);
     $this->assertTrue($needRehashing);
 }
Beispiel #2
0
 private function makeInstall($ns)
 {
     $this->_isValidInstallData($ns);
     $this->_createConfigurationFile($ns);
     $link = @mysql_connect($ns->get('db_host'), $ns->get('db_user'), $ns->get('db_pass'));
     if (!$link) {
         throw new Exception('Could not connect to database');
     }
     $db_selected = @mysql_select_db($ns->get('db_name'), $link);
     if (!$db_selected) {
         throw new Exception('Could not select database');
     }
     mysql_query("SET NAMES 'utf8'");
     /*
     $qry = mysql_query("SHOW TABLES;");
     while($res = mysql_fetch_array($qry)) {
         $dropqry = mysql_query("DROP TABLE $res[0];");
     }
     */
     $sql = file_get_contents(BB_PATH_SQL);
     if (!$sql) {
         throw new Exception('Could not read structure.sql file');
     }
     $sql_content = file_get_contents(BB_PATH_SQL_DATA);
     if (!$sql_content) {
         throw new Exception('Could not read structure.sql file');
     }
     $sql .= $sql_content;
     $sql = preg_split('/\\;[\\r]*\\n/ism', $sql);
     $sql = array_map('trim', $sql);
     $err = '';
     foreach ($sql as $query) {
         if (!trim($query)) {
             continue;
         }
         $res = mysql_query($query, $link);
         $err .= mysql_error();
     }
     if (!empty($err)) {
         throw new Exception($err);
     }
     $passwordObject = new \Box_Password();
     $sql = "INSERT INTO admin (role, name, email, pass, protected, created_at, updated_at) VALUES('admin', '%s', '%s', '%s', 1, NOW(), NOW());";
     $sql = sprintf($sql, mysql_real_escape_string($ns->get('admin_name')), mysql_real_escape_string($ns->get('admin_email')), mysql_real_escape_string($passwordObject->hashIt($ns->get('admin_pass'))));
     $res = mysql_query($sql, $link);
     if (!$res) {
         throw new Exception(mysql_error());
     }
     mysql_close($link);
     try {
         $this->_sendMail($ns);
     } catch (Exception $e) {
         // email was not sent but that is not a problem
     }
     return true;
 }