PluginProbe
404 Solution / trunk
404 Solution vtrunk
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / feedback / FeedbackReportUuid.php

FeedbackReportUuid.php in 404 Solution trunk, at includes/feedback/FeedbackReportUuid.php

32 lines 1.1 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 /**
8 * Generates random report identifiers for queued feedback envelopes.
9 */
10 class ABJ_404_Solution_FeedbackReportUuid {
11
12 public static function generate(): string {
13 try {
14 $data = random_bytes(16);
15 // allow-silent-catch: random_bytes only throws when CSPRNG unavailable; fallback to wp_generate_password / mt_rand still produces a valid transient key
16 } catch (\Throwable $e) {
17 $data = '';
18 if (function_exists('wp_generate_password')) {
19 $data = (string)wp_generate_password(16, true, true);
20 $data = substr($data . str_repeat("\0", 16), 0, 16);
21 }
22 if ($data === '' || strlen($data) < 16) {
23 $data = str_pad((string)mt_rand(), 16, "\0");
24 $data = substr($data, 0, 16);
25 }
26 }
27 $data[6] = chr((ord($data[6]) & 0x0f) | 0x40);
28 $data[8] = chr((ord($data[8]) & 0x3f) | 0x80);
29 return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
30 }
31 }
32