/**
* guidV4 ()
* ------------------------------------------------------------------------
*
* generates a GUID with 36 characters including hyphens
*
* Usage: $tmp = self::guidV4();
*
* |-4 |- 8 9 a b
* Format: XXXXXXXXXXXX-XXXX-xXXX-yXXX-XXXXXXXXXXXX
*
* @return string
*/
public static function guidV4()
{
// this is for MS Windows Systems.
if (function_exists('com_create_guid') === true)
{
return trim(com_create_guid(), '{}');
}
$data = openssl_random_pseudo_bytes(16);
$data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100
$data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
/**
* generateToken ()
* --------------------------------------------------------------------
*
* Generates an array with selector | validator then it will hash them
*
* USAGE: generateToken();
*
* @return array
*/
private function generateToken()
{
/**
* If you define a namespace, you can prefix it to the GUID
* Just un-remark the line below and rem the other line.
*/
//$tmp = Uuid_Namespace."-".self::guid_v4();
$tmp = self::guidV4();
$tokenData = array(
'selector' => $tmp,
'token' => base64_encode(hash('sha256', $tmp)),
);
return $tokenData;
}