| @@ -1,70 +1,47 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | if (!defined('ABSPATH')) exit; |
| 3 | 3 | if (!class_exists('WPRRecover')) : |
| 4 | 4 | class WPRRecover { |
| 5 | - public static $default_secret_key = 'bv_default_secret_key'; | |
| 5 | + public static $default_secret_key = 'bvSecretKey'; | |
| 6 | 6 | |
| 7 | 7 | public static function defaultSecret($settings) { |
| 8 | 8 | $secret = self::getDefaultSecret($settings); |
| 9 | 9 | if (empty($secret)) { |
| 10 | - $secret = WPRRecover::refreshDefaultSecret($settings); | |
| 10 | + $secret = WPRAccount::randString(32); | |
| 11 | + self::updateDefaultSecret($settings, $secret); | |
| 11 | 12 | } |
| 12 | 13 | return $secret; |
| 13 | 14 | } |
| 14 | 15 | |
| 15 | - public static function refreshDefaultSecret($settings) { | |
| 16 | - $key_details = array(); | |
| 17 | - $key_details["key"] = WPRAccount::randString(32); | |
| 18 | - $key_details["expires_at"] = time() + (24 * 60 * 60); | |
| 19 | - | |
| 20 | - $settings->updateOption(self::$default_secret_key, $key_details); | |
| 21 | - | |
| 22 | - return $key_details["key"]; | |
| 23 | - } | |
| 24 | - | |
| 25 | - | |
| 26 | 16 | public static function deleteDefaultSecret($settings) { |
| 27 | 17 | $settings->deleteOption(self::$default_secret_key); |
| 28 | 18 | } |
| 29 | 19 | |
| 30 | 20 | public static function getDefaultSecret($settings) { |
| 31 | - $key_details = $settings->getOption(self::$default_secret_key); | |
| 21 | + return $settings->getOption(self::$default_secret_key); | |
| 22 | + } | |
| 32 | 23 | |
| 33 | - if (is_array($key_details) && $key_details["expires_at"] > time()) { | |
| 34 | - return $key_details["key"]; | |
| 35 | - } | |
| 36 | - | |
| 37 | - return null; | |
| 24 | + public static function updateDefaultSecret($settings, $secret) { | |
| 25 | + $settings->updateOption(self::$default_secret_key, $secret); | |
| 38 | 26 | } |
| 39 | 27 | |
| 40 | - public static function getSecretStatus($settings) { | |
| 41 | - $key_details = $settings->getOption(self::$default_secret_key); | |
| 42 | - $status = 'ACTIVE'; | |
| 43 | - if (!is_array($key_details)) { | |
| 44 | - $status = 'DELETED'; | |
| 45 | - } elseif ($key_details["expires_at"] <= time()) { | |
| 46 | - $status = 'EXPIRED'; | |
| 28 | + public static function validate($pubkey) { | |
| 29 | + if ($pubkey && strlen($pubkey) >= 32) { | |
| 30 | + return true; | |
| 31 | + } else { | |
| 32 | + return false; | |
| 47 | 33 | } |
| 48 | - | |
| 49 | - return $status; | |
| 50 | 34 | } |
| 51 | 35 | |
| 52 | - public static function validate($key) { | |
| 53 | - return $key && strlen($key) >= 32; | |
| 54 | - } | |
| 55 | - | |
| 56 | 36 | public static function find($settings, $pubkey) { |
| 57 | 37 | if (!self::validate($pubkey)) { |
| 58 | 38 | return null; |
| 59 | 39 | } |
| 60 | - | |
| 61 | 40 | $secret = self::getDefaultSecret($settings); |
| 62 | - if (!self::validate($secret)) { | |
| 63 | - return null; | |
| 41 | + if (!empty($secret) && (strlen($secret) >= 32)) { | |
| 42 | + $account = new WPRAccount($settings, $pubkey, $secret); | |
| 64 | 43 | } |
| 65 | - | |
| 66 | - $account = new WPRAccount($settings, $pubkey, $secret); | |
| 67 | 44 | return $account; |
| 68 | 45 | } |
| 69 | 46 | } |
| 70 | 47 | endif; |