Array_To_CSV.php
3 years ago
Currency.php
3 years ago
Device.php
2 years ago
Number_Formatter.php
3 years ago
Option.php
2 years ago
Request.php
2 years ago
Salt.php
3 years ago
Security.php
3 years ago
Singleton.php
2 years ago
String_Util.php
3 years ago
URL.php
3 years ago
WP_Async_Request.php
3 years ago
WordPress_Site_Date_Format_Pattern.php
3 years ago
Salt.php
37 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED\IAWP\Utils; |
| 4 | |
| 5 | class Salt |
| 6 | { |
| 7 | /* |
| 8 | * Used for salting visitor hashes. |
| 9 | */ |
| 10 | public static function visitor_token_salt() : string |
| 11 | { |
| 12 | return self::get_salt_option('iawp_salt'); |
| 13 | } |
| 14 | /* |
| 15 | * Primarily used for salting request payloads. |
| 16 | */ |
| 17 | public static function request_payload_salt() : string |
| 18 | { |
| 19 | return self::get_salt_option('iawp_request_payload_salt'); |
| 20 | } |
| 21 | private static function get_salt_option($name) : string |
| 22 | { |
| 23 | $salt = \get_option($name); |
| 24 | if ($salt == \false) { |
| 25 | $salt = self::generate_salt(); |
| 26 | \update_option($name, $salt); |
| 27 | } |
| 28 | return $salt; |
| 29 | } |
| 30 | private static function generate_salt() : string |
| 31 | { |
| 32 | $length = 32; |
| 33 | $bytes = \random_bytes($length); |
| 34 | return \substr(\strtr(\base64_encode($bytes), '+', '.'), 0, 44); |
| 35 | } |
| 36 | } |
| 37 |