FHC Helper

This commit is contained in:
Paminger
2016-06-29 08:41:02 +02:00
parent 6af45f99f6
commit 9a44c818ea
31 changed files with 957 additions and 71 deletions
-35
View File
@@ -289,41 +289,6 @@ class MessageLib
return $result;
}
/**
* generateToken() - generates a new token for reading Messages from external
*
* @return string
*/
function generateToken($length = 64)
{
// For PHP 7 you can use random_bytes()
if(function_exists('random_bytes'))
{
$token = base64_encode(random_bytes($length));
//base64 is about 33% longer, so we need to truncate the result
return strtr(substr($token, 0, $length), '+/=', '-_,');
}
// for PHP >=5.3 and <7
if(function_exists('openssl_random_pseudo_bytes'))
{
$token = base64_encode(openssl_random_pseudo_bytes($length, $strong));
// is the token strong enough?
if($strong == true)
return strtr(substr($token, 0, $length), '+/=', '-_,');
}
//fallback to mt_rand if php < 5.3 or no openssl available
$characters = '0123456789';
$characters .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/+';
$charactersLength = strlen($characters)-1;
$token = '';
//select some random characters
for ($i = 0; $i < $length; $i++)
$token .= $characters[mt_rand(0, $charactersLength)];
return $token;
}
// ------------------------------------------------------------------------