function forgot_password($email) { if (!MO2f_Utility::is_curl_installed()) { $message = 'Please enable curl extension. <a href="admin.php?page=miniOrange_2_factor_settings&mo2f_tab=mo2f_help">Click here</a> for the steps to enable curl or check Help & Troubleshooting.'; return json_encode(array("status" => 'ERROR', "message" => $message)); } $url = get_option('mo2f_host_name') . '/moas/rest/customer/password-reset'; $ch = curl_init($url); $fields = array('email' => $email); $field_string = json_encode($fields); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch, CURLOPT_ENCODING, ""); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); # required for https urls curl_setopt($ch, CURLOPT_MAXREDIRS, 10); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'charset: UTF - 8', 'Authorization: Basic')); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $field_string); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_TIMEOUT, 20); $content = curl_exec($ch); if (curl_errno($ch)) { return null; } curl_close($ch); return $content; }
function register_kba_details($email, $question1, $answer1, $question2, $answer2, $question3, $answer3) { if (!MO2f_Utility::is_curl_installed()) { $message = 'Please enable curl extension. <a href="admin.php?page=miniOrange_2_factor_settings&mo2f_tab=mo2f_help">Click here</a> for the steps to enable curl or check Help & Troubleshooting.'; return json_encode(array("status" => 'ERROR', "message" => $message)); } $url = get_option('mo2f_host_name') . '/moas/api/auth/register'; $ch = curl_init($url); /* The customer Key provided to you */ $customerKey = get_option('mo2f_customerKey'); /* The customer API Key provided to you */ $apiKey = get_option('mo2f_api_key'); /* Current time in milliseconds since midnight, January 1, 1970 UTC. */ $currentTimeInMillis = round(microtime(true) * 1000); /* Creating the Hash using SHA-512 algorithm */ $stringToHash = $customerKey . number_format($currentTimeInMillis, 0, '', '') . $apiKey; $hashValue = hash("sha512", $stringToHash); $customerKeyHeader = "Customer-Key: " . $customerKey; $timestampHeader = "Timestamp: " . number_format($currentTimeInMillis, 0, '', ''); $authorizationHeader = "Authorization: " . $hashValue; $q_and_a_list = "[{\"question\":\"" . $question1 . "\",\"answer\":\"" . $answer1 . "\" },{\"question\":\"" . $question2 . "\",\"answer\":\"" . $answer2 . "\" },{\"question\":\"" . $question3 . "\",\"answer\":\"" . $answer3 . "\" }]"; $field_string = "{\"customerKey\":\"" . $customerKey . "\",\"username\":\"" . $email . "\",\"questionAnswerList\":" . $q_and_a_list . "}"; curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch, CURLOPT_ENCODING, ""); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); # required for https urls curl_setopt($ch, CURLOPT_MAXREDIRS, 10); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", $customerKeyHeader, $timestampHeader, $authorizationHeader)); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $field_string); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_TIMEOUT, 20); $content = curl_exec($ch); if (curl_errno($ch)) { return null; } curl_close($ch); return $content; }