my_LoginError(); } } $hash = null; /* // Debug // if ( $mail ) $response['mail'] = $mail; else $response['login'] = $login; $response['pw'] = $password; */ // By E-mail // if ($mail) { // Search user_table for a matching e-mail. $data = user_GetIdAndHashByMail($mail); if ($data) { $response['id'] = intval($data['id']); $hash = $data['hash']; } else { my_LoginError(); } } else { // Search for the user's node by slug // $response['id'] = intval(node_GetNodeIdByParentIdAndSlug(CMW_NODE_USER, $login)); // If a valid ID, retrieve the hash if ($response['id'] > 0) { $hash = user_GetHashById($response['id']); } else { my_LoginError(); }
function main() { $out = ""; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $out .= print_r($_POST, true); $out .= "<br />"; // Required Fields in the POST data // if (!isset($_POST['login'])) { return; } if (!isset($_POST['password'])) { return; } //if ( !isset($_POST['hashword']) ) return; // Password // $password = $_POST['password']; if (empty($password)) { return; } $login = $_POST['login']; // Can Login 3 ways: // - User Name (slug) // - Email // - User ID $mail = sanitize_Email($login); $id = sanitize_Id($login); $slug = sanitize_Slug($login); $hash = ""; if (!empty($mail)) { $out .= "By Mail<br />"; $data = user_GetIdAndHashByMail($mail); $id = $data['id']; $hash = $data['hash']; } else { if (!empty($id)) { $out .= "By User ID<br />"; $hash = user_GetHashById($id); } else { if (!empty($slug)) { $out .= "By Slug<br />"; $id = node_GetNodeIdByParentIdAndSlug(CMW_NODE_USER, $slug); if ($id > 0) { $hash = user_GetHashById($id); } } else { $out .= "Bad Login Method<br />"; } } } $success = user_VerifyPassword($password, $hash); $out .= "Verify: " . ($success ? "Success!" : "failed") . "<br />"; if ($success) { user_StartSession(true); user_SetLoginToken(); user_SetID($id); user_EndSession(); } $out .= "<br />"; } return $out; }