BladeOne.php
2 years ago
CSV.php
9 months ago
Calculations.php
2 years ago
Currency.php
8 months ago
Device.php
1 year ago
Device_Cache.php
2 years ago
Dir.php
5 months ago
Format.php
5 months ago
Link_Validator.php
6 months ago
Number_Formatter.php
5 months ago
Obj.php
6 months ago
Request.php
11 months ago
Salt.php
1 year ago
Security.php
1 year ago
Server.php
2 years ago
Singleton.php
2 years ago
String_Util.php
2 years ago
Timezone.php
5 months ago
URL.php
6 months ago
WP_Async_Request.php
1 year ago
Salt.php
43 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Utils; |
| 4 | |
| 5 | /** @internal */ |
| 6 | class Salt |
| 7 | { |
| 8 | /* |
| 9 | * Used for salting visitor hashes. |
| 10 | */ |
| 11 | public static function visitor_token_salt() : string |
| 12 | { |
| 13 | return self::get_salt_option('iawp_salt'); |
| 14 | } |
| 15 | public static function refresh_visitor_token_salt() : string |
| 16 | { |
| 17 | \delete_option('iawp_salt'); |
| 18 | return self::get_salt_option('iawp_salt'); |
| 19 | } |
| 20 | /* |
| 21 | * Primarily used for salting request payloads. |
| 22 | */ |
| 23 | public static function request_payload_salt() : string |
| 24 | { |
| 25 | return self::get_salt_option('iawp_request_payload_salt'); |
| 26 | } |
| 27 | private static function get_salt_option($name) : string |
| 28 | { |
| 29 | $salt = \get_option($name); |
| 30 | if (!$salt) { |
| 31 | $salt = self::generate_salt(); |
| 32 | \update_option($name, $salt, \true); |
| 33 | } |
| 34 | return $salt; |
| 35 | } |
| 36 | private static function generate_salt() : string |
| 37 | { |
| 38 | $length = 32; |
| 39 | $bytes = \random_bytes($length); |
| 40 | return \substr(\strtr(\base64_encode($bytes), '+', '.'), 0, 44); |
| 41 | } |
| 42 | } |
| 43 |