- var_dump: documentation ( source)
- hash_hmac: documentation ( source)
<?php
// Spoke
$key = 'This is the key';
$secret = "TRUSTNO1";
$request = array(
'license' => $key,
'authentication' => hash_hmac('sha256', $key, $secret),
);
?>
<?php
// Hub
$key_index = array(
'This is the key' => 'TRUSTNO1'
);
if ($auth = $request['authentication']) {
if ($key = $request['license'] && $secret = $key_index[$key]) {
$new_hash = hash_hmac('sha256', $key, $secret);
if (hash_compare($new_hash, $auth)) {
var_dump('Authenticated.');
} else {
var_dump('Not authenticated');
}
}
}