unlink($dir."/".$unique_name);
}
else
- $unique_name = uniqid('');
+ $unique_name = random_id();
//save the file
move_uploaded_file($tmpname, $dir."/".$unique_name);
return preg_replace('/[^a-zA-Z0-9.\-_]/', '_', $filename);
}
-?>
\ No newline at end of file
+/*
+ This function aims to generate cryptographically strong random identifier.
+ Result identifier has length 4[strength/8/3]
+*/
+function random_id($strength = 128)
+{
+ $n = ceil($strength/8);
+
+ if (function_exists('openssl_random_pseudo_bytes'))
+ $bin = openssl_random_pseudo_bytes($n, $cstrong); // openssl on php 5.3 and up
+ else if (file_exists('/dev/urandom'))
+ $bin = file_get_contents('/dev/urandom', false, null, -1, $n); // linux std random device
+ else {
+ $bin = '';
+ for($i=0; $i < $n; $i++)
+ $bin .= chr(mt_rand(0, 255)); // Mersene Twister generator
+ }
+ $id = strtr(base64_encode($bin), '+/', '-_'); // see RFC 4648 Section 5
+
+ return $id;
+}
{
global $Ajax, $hidden_fields;
- $_SESSION['csrf_token'] = hash('sha256', uniqid(mt_rand(), true));
+ $_SESSION['csrf_token'] = random_id();
if ($breaks)
br($breaks);
hidden('_focus');
$rtl = ($_SESSION['language']->dir == 'rtl');
$this->code = strtolower($_SESSION['language']->encoding);
$this->filename = $filename.".xls";
- $this->unique_name = uniqid('').".xls";
+ $this->unique_name = random_id().".xls";
$this->path = company_path(). '/pdf_files';
$this->Spreadsheet_Excel_Writer_Workbook($this->path."/".$this->unique_name);
//$this->setCountry(48);
// are world readable
if ($email == 1)
$fname = $dir.'/'.$this->filename;
- else
- $fname = $dir.'/'.uniqid('').'.pdf';
+ else
+ $fname = $dir.'/'.random_id().'.pdf';
$this->Output($fname, 'F');
if ($email == 1)
$pg->skin = $graph_skin;
$pg->built_in = false;
$pg->latin_notation = ($decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".");
- $filename = company_path(). "/pdf_files/". uniqid("").".png";
+ $filename = company_path(). "/pdf_files/". random_id().".png";
$pg->display($filename, true);
$w = $pg->width / 1.5;
$h = $pg->height / 1.5;
$pg->skin = $graph_skin;
$pg->built_in = false;
$pg->latin_notation = ($decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".");
- $filename = company_path(). "/pdf_files/". uniqid("").".png";
+ $filename = company_path(). "/pdf_files/". random_id().".png";
$pg->display($filename, true);
$w = $pg->width / 1.5;
$h = $pg->height / 1.5;
$pg->skin = $graph_skin;
$pg->built_in = false;
$pg->latin_notation = ($decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".");
- $filename = company_path(). "/pdf_files/". uniqid("").".png";
+ $filename = company_path(). "/pdf_files/". random_id().".png";
$pg->display($filename, true);
$w = $pg->width / 1.5;
$h = $pg->height / 1.5;
$pg->skin = $graph_skin;
$pg->built_in = false;
$pg->latin_notation = ($decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".");
- $filename = company_path(). "/pdf_files/". uniqid("").".png";
+ $filename = company_path(). "/pdf_files/". random_id().".png";
$pg->display($filename, true);
$w = $pg->width / 1.5;
$h = $pg->height / 1.5;