| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) exit; |
| 3 |
if (!class_exists('WPRRecover')) : |
| 4 |
class WPRRecover { |
| 5 |
public static $default_secret_key = 'bvSecretKey'; |
| 6 |
|
| 7 |
public static function defaultSecret($settings) { |
| 8 |
$secret = self::getDefaultSecret($settings); |
| 9 |
if (empty($secret)) { |
| 10 |
$secret = WPRRecover::refreshDefaultSecret($settings); |
| 11 |
} |
| 12 |
return $secret; |
| 13 |
} |
| 14 |
|
| 15 |
public static function refreshDefaultSecret($settings) { |
| 16 |
$secret = WPRAccount::randString(32); |
| 17 |
self::updateDefaultSecret($settings, $secret); |
| 18 |
return $secret; |
| 19 |
} |
| 20 |
|
| 21 |
public static function deleteDefaultSecret($settings) { |
| 22 |
$settings->deleteOption(self::$default_secret_key); |
| 23 |
} |
| 24 |
|
| 25 |
public static function getDefaultSecret($settings) { |
| 26 |
return $settings->getOption(self::$default_secret_key); |
| 27 |
} |
| 28 |
|
| 29 |
public static function updateDefaultSecret($settings, $secret) { |
| 30 |
$settings->updateOption(self::$default_secret_key, $secret); |
| 31 |
} |
| 32 |
|
| 33 |
public static function validate($pubkey) { |
| 34 |
if ($pubkey && strlen($pubkey) >= 32) { |
| 35 |
return true; |
| 36 |
} else { |
| 37 |
return false; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
public static function find($settings, $pubkey) { |
| 42 |
if (!self::validate($pubkey)) { |
| 43 |
return null; |
| 44 |
} |
| 45 |
$secret = self::getDefaultSecret($settings); |
| 46 |
if (!empty($secret) && (strlen($secret) >= 32)) { |
| 47 |
$account = new WPRAccount($settings, $pubkey, $secret); |
| 48 |
} |
| 49 |
return $account; |
| 50 |
} |
| 51 |
} |
| 52 |
endif; |