public static function getToken($type = 'token')
{
$app = Factory::getApplication();
$secret = $app->get('secret');
$secretPartA = substr($secret, mt_rand(4, 15), mt_rand(0, 10));
$secretPartB = substr($secret, mt_rand(4, 15), mt_rand(0, 10));
$saltArray = array('a', '0', 'c', '1', 'e', '2', 'h', '3', 'i', '4', 'k', '5', 'm', '6', 'o', '7', 'q', '8', 'r', '0', 'u', '1', 'w', '2', 'y');
$randA = mt_rand(0, 9999);
$randB = mt_rand(0, $randA);
$randC = mt_rand(0, $randB);
$randD = mt_rand(0, 24);
$randD2 = mt_rand(0, 24);
$salt = md5('string ' . $secretPartA . date('s') . $randA . str_replace($randC, $randD, date('r')) . $secretPartB . 'end string');
$salt = str_replace($saltArray[$randD], $saltArray[$randD2], $salt);
if ($type > 100) {
$salt = md5($salt);
}
// use password_hash since php 5.5.0
$salt = crypt($salt, $salt);
$rT = $randC + $randA;
if ($rT < 1) {
$rT = 1;
}
$time = (int) time() * $randB / $rT;
$token = hash('sha256', $salt . $time . time());
if ($type == 'folder') {
return substr($token, $randD, 16);
} else {
return $token;
}
}