PluginProbe
Booking Package / trunk
Booking Package vtrunk
1.7.28 1.7.27 1.7.26 1.7.24 1.7.25 1.7.23 1.7.22 1.7.21 1.7.20 1.7.19 1.7.18 1.7.17 1.7.16 1.7.15 1.7.14 1.7.13 1.7.12 1.7.11 1.7.10 trunk 1.5.30 1.5.31 1.5.32 1.5.33 1.5.35 All 183 releases
booking-package / lib / Nonce.php

Nonce.php in Booking Package trunk, at lib/Nonce.php

66 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 ?>