| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
class booking_package_nonce { |
| 8 |
|
| 9 |
private $session_id = null; |
| 10 |
|
| 11 |
public function __construct($prefix, $pluginName, $ajaxNonceFunction) { |
| 12 |
|
| 13 |
if ($ajaxNonceFunction !== 'custom_nonce_validation') { |
| 14 |
|
| 15 |
return false; |
| 16 |
|
| 17 |
} |
| 18 |
|
| 19 |
if (session_status() == PHP_SESSION_NONE) { |
| 20 |
|
| 21 |
session_start(); |
| 22 |
session_write_close(); |
| 23 |
|
| 24 |
} |
| 25 |
|
| 26 |
$this->session_id = session_id(); |
| 27 |
if (empty($this->session_id) === true) { |
| 28 |
|
| 29 |
$this->session_id = get_current_user_id(); |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
} |
| 34 |
|
| 35 |
public function create($action) { |
| 36 |
|
| 37 |
$uniqid = uniqid(); |
| 38 |
$unique = get_site_url(); |
| 39 |
$timestamp = time(); |
| 40 |
#$nonce = hash_hmac('sha256', $action . get_current_user_id() . $timestamp, $secret_key) . '|' . $timestamp; |
| 41 |
$nonce = wp_hash($action . $this->session_id . $timestamp, $unique) . '|' . $timestamp; |
| 42 |
return $nonce; |
| 43 |
|
| 44 |
} |
| 45 |
|
| 46 |
public function verify($nonce, $action) { |
| 47 |
|
| 48 |
$unique = get_site_url(); |
| 49 |
list($hash, $timestamp) = explode('|', $nonce); |
| 50 |
$expiration = 1440 * 60; |
| 51 |
if ((time() - $timestamp) > $expiration) { |
| 52 |
|
| 53 |
return false; |
| 54 |
|
| 55 |
} |
| 56 |
|
| 57 |
#$expected_hash = hash_hmac('sha256', $action . get_current_user_id() . $timestamp, 'your_secret_key'); |
| 58 |
$expected_hash = wp_hash($action . $this->session_id . $timestamp, $unique); |
| 59 |
return hash_equals($expected_hash, $hash); |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
?> |