diff --git a/database/loginAccount.php b/database/loginAccount.php index eab9488..83b7538 100644 --- a/database/loginAccount.php +++ b/database/loginAccount.php @@ -25,19 +25,17 @@ if (!password_verify($password, $user["password"])) { exitWithMessage(json_encode(["success" => false, "message" => "Invalid username or password"])); } -$uid = $user['uid']; -$token = $user['game_session_token']; -if (!$token || strlen(trim($token)) !== 512) $token = bin2hex(random_bytes(256)); - +$id = $user['id']; +$token = $user['token']; $ip = getIPAddress(); -$stmt = $conn->prepare("UPDATE users SET latest_ip = ?, game_session_token = ? WHERE uid = ?"); -$stmt->bind_param("ssi", $ip, $token, $uid); +$stmt = $conn->prepare("UPDATE users SET latest_ip = ?, token = ? WHERE id = ?"); +$stmt->bind_param("ssi", $ip, $token, $id); $stmt->execute(); if ($currentHighScore > $user['highScore']) { - $stmt = $conn->prepare("UPDATE users SET highScore = ? WHERE uid = ?"); - $stmt->bind_param("ii", $currentHighScore, $uid); + $stmt = $conn->prepare("UPDATE users SET highScore = ? WHERE id = ?"); + $stmt->bind_param("ii", $currentHighScore, $id); $stmt->execute(); $user['highScore'] = $currentHighScore; } @@ -47,7 +45,7 @@ $data = ["session" => $token]; if ($loginType === "0") { $data += [ "username" => $user['username'], - "userid" => $uid, + "id" => $id, "highscore" => (string)$user['highScore'], "icon" => (int)$user['icon'], "overlay" => (int)$user['overlay'], @@ -63,7 +61,7 @@ if ($loginType === "0") { } elseif ($loginType === "1") { $data += [ "username" => $user['username'], - "userid" => $uid + "id" => $id ]; } diff --git a/database/registerAccount.php b/database/registerAccount.php index 0b4cc04..8cb2497 100644 --- a/database/registerAccount.php +++ b/database/registerAccount.php @@ -21,7 +21,7 @@ if (!preg_match('/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d!@#$%^&*()_\-+=]{8,}$/', $pass exitWithMessage(json_encode(["success" => false, "message" => "Password must be at least 8 characters with at least one letter and one number"])); } -$stmt = $conn->prepare("SELECT uid FROM users WHERE username = ? OR email = ?"); +$stmt = $conn->prepare("SELECT id FROM users WHERE username = ? OR email = ?"); $stmt->bind_param("ss", $username, $email); $stmt->execute(); $res = $stmt->get_result(); @@ -35,7 +35,7 @@ $token = bin2hex(random_bytes(256)); $ip = getIPAddress(); $time = time(); -$stmt = $conn->prepare("INSERT INTO users (game_session_token, username, password, email, register_time, latest_ip) VALUES (?, ?, ?, ?, ?, ?)"); +$stmt = $conn->prepare("INSERT INTO users (token, username, password, email, register_time, latest_ip) VALUES (?, ?, ?, ?, ?, ?)"); $stmt->bind_param("ssssis", $token, $username, $hashed, $email, $time, $ip); $stmt->execute();