Editing: /home/goacom/public_html/scratch_extract/security-center.php
<?php session_start(); // 1. Database Connection $host = 'localhost'; $db_user = 'tishanw1_melbets'; // Change this $db_pass = 'tishanw1_melbets'; // Change this $db_name = 'tishanw1_melbets'; $conn = new mysqli($host, $db_user, $db_pass, $db_name); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Get User ID $user_id = isset($_SESSION['user_id']) ? $_SESSION['user_id'] : 0; if ($user_id == 0) { header("Location: login.php"); exit(); } // Handle Logout if (isset($_GET['logout'])) { session_destroy(); header("Location: login.php"); exit(); } // Handle POST Requests for Forms $message = ""; $msg_type = ""; if ($_SERVER['REQUEST_METHOD'] === 'POST') { // A. Personal Information (Nickname & Email) if (isset($_POST['action']) && $_POST['action'] == 'update_personal') { $nickname = $_POST['nickname']; $email = $_POST['email']; // Check if row exists $check = $conn->query("SELECT id FROM user_details WHERE user_id = $user_id"); if ($check->num_rows > 0) { $stmt = $conn->prepare("UPDATE user_details SET nickname = ?, email = ? WHERE user_id = ?"); $stmt->bind_param("ssi", $nickname, $email, $user_id); } else { $stmt = $conn->prepare("INSERT INTO user_details (user_id, nickname, email) VALUES (?, ?, ?)"); $stmt->bind_param("iss", $user_id, $nickname, $email); } if ($stmt->execute()) { $message = "Personal information updated successfully."; $msg_type = "success"; } else { $message = "Error updating info."; $msg_type = "error"; } $stmt->close(); } // B. Change Login Password if (isset($_POST['action']) && $_POST['action'] == 'change_password') { $old_pass = $_POST['old_password']; $new_pass = $_POST['new_password']; // Verify old password $stmt = $conn->prepare("SELECT password FROM users WHERE id = ?"); $stmt->bind_param("i", $user_id); $stmt->execute(); $result = $stmt->get_result(); $user = $result->fetch_assoc(); $stmt->close(); if (password_verify($old_pass, $user['password'])) { $hashed_new = password_hash($new_pass, PASSWORD_DEFAULT); $update = $conn->prepare("UPDATE users SET password = ? WHERE id = ?"); $update->bind_param("si", $hashed_new, $user_id); if ($update->execute()) { $message = "Password changed successfully."; $msg_type = "success"; } $update->close(); } else { $message = "Old password is incorrect."; $msg_type = "error"; } } // C. Set Transaction Password if (isset($_POST['action']) && $_POST['action'] == 'set_trans_pass') { $trans_pass = $_POST['transaction_password']; $hashed_trans = password_hash($trans_pass, PASSWORD_DEFAULT); // Check if already exists $check = $conn->query("SELECT id FROM user_transaction_passwords WHERE user_id = $user_id"); if ($check->num_rows > 0) { $stmt = $conn->prepare("UPDATE user_transaction_passwords SET transaction_password = ? WHERE user_id = ?"); $stmt->bind_param("si", $hashed_trans, $user_id); } else { $stmt = $conn->prepare("INSERT INTO user_transaction_passwords (user_id, transaction_password) VALUES (?, ?)"); $stmt->bind_param("is", $user_id, $hashed_trans); } if ($stmt->execute()) { $message = "Transaction password set successfully."; $msg_type = "success"; } $stmt->close(); } } // Fetch Data for View // 1. Last Login Info $user_query = $conn->query("SELECT last_login_ip, last_login_time FROM users WHERE id = $user_id"); $user_data = $user_query->fetch_assoc(); $last_ip = $user_data['last_login_ip'] ?? 'Not available'; $last_time = $user_data['last_login_time'] ?? 'Not available'; // 2. Check Personal Info $personal_check = $conn->query("SELECT * FROM user_details WHERE user_id = $user_id"); $personal_data = $personal_check->fetch_assoc(); // 3. Check E-Wallet (Withdrawal Methods) $wallet_check = $conn->query("SELECT COUNT(*) as count FROM user_withdrawal_methods WHERE user_id = $user_id"); $wallet_data = $wallet_check->fetch_assoc(); $has_wallet = $wallet_data['count'] > 0; // 4. Check Transaction Password $trans_check = $conn->query("SELECT id FROM user_transaction_passwords WHERE user_id = $user_id"); $has_trans_pass = $trans_check->num_rows > 0; // Calculate Security Percentage // Base: 25% // Personal Info: +25% // E-Wallet: +25% // Trans Password: +25% $percentage = 25; if ($personal_data) $percentage += 25; if ($has_wallet) $percentage += 25; if ($has_trans_pass) $percentage += 25; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="description" content="MELBETE - Official Gaming & Betting Platform." /> <title>MELBETE - Security Center</title> <link rel="stylesheet" href="index.css" /> <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800;900&display=swap" rel="stylesheet" /> </head> <body> <div id="root"> <div class="w-full bg-bodyColor"> <div class="max-w-[1000px] mx-auto"> <!-- Header --> <div class="bg-[#333]"> <div class="flex justify-between items-center h-12" style="background: rgb(240, 104, 39);"> <a href="javascript:history.back()" class="text-white cursor-pointer text-[26px] w-16 flex items-center justify-center"> <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"> <path d="M217.9 256L345 129c9.4-9.4 9.4-24.6 0-33.9-9.4-9.4-24.6-9.3-34 0L167 239c-9.1 9.1-9.3 23.7-.7 33.1L310.9 417c4.7 4.7 10.9 7 17 7s12.3-2.3 17-7c9.4-9.4 9.4-24.6 0-33.9L217.9 256z"></path> </svg> </a> <div class="w-full text-white text-[19px] text-center"> Security Center </div> </div> </div> <!-- Main Content --> <div class="min-h-screen bg-gray-50 flex justify-center p-4"> <div class="bg-white rounded-xl shadow-md w-full max-w-md p-5"> <!-- Alert Message --> <?php if($message): ?> <div class="mb-4 p-3 rounded text-center text-sm <?php echo $msg_type == 'success' ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-700'; ?>"> <?php echo $message; ?> </div> <?php endif; ?> <!-- Safety Percentage Section --> <div class="mb-4"> <h3 class="font-semibold text-gray-700 mb-2">Safety percentage : <span class="text-green-500"> <?php if($percentage == 100) echo "High"; elseif($percentage >= 50) echo "Medium"; else echo "Low"; ?> </span></h3> <div class="flex items-center space-x-4"> <div class="relative w-16 h-16"> <svg class="absolute top-0 left-0 w-16 h-16 transform -rotate-90" viewBox="0 0 36 36"> <circle cx="18" cy="18" r="15.9155" fill="none" stroke="#e5e7eb" stroke-width="3"></circle> <circle cx="18" cy="18" r="15.9155" fill="none" stroke="#22c55e" stroke-width="3" stroke-dasharray="100, 100" stroke-dashoffset="<?php echo 100 - $percentage; ?>" stroke-linecap="round" class="transition-all duration-[1s] ease-out"></circle> </svg> <div class="absolute inset-0 flex items-center justify-center text-green-500 font-semibold text-sm" style="margin-left: 14px;"> <?php echo $percentage; ?>% </div> </div> <div class="text-xs text-gray-600"> <div class="flex items-center gap-1 mb-1"> <?php $stars = $percentage / 20; // 5 stars max for($i=0; $i<5; $i++) { if($i < $stars) echo "⚡"; else echo "⚪"; } ?> <span class="text-green-500 font-semibold"> <?php if($percentage == 100) echo "High"; elseif($percentage >= 50) echo "Medium"; else echo "Low"; ?> </span> </div> <p>Last login IP :</p> <p class="text-gray-500 break-words"><?php echo htmlspecialchars($last_ip); ?></p> <p class="mt-1">Last login time :</p> <p class="text-gray-500"><?php echo htmlspecialchars($last_time); ?></p> </div> </div> </div> <div class="text-center text-green-500 text-sm mb-4 font-medium"> Your account security level is <b><?php echo ($percentage == 100) ? 'high' : 'medium'; ?> .</b> </div> <!-- Options List --> <div class="divide-y"> <!-- 1. Personal Information (Popup Trigger) --> <div> <div class="flex items-center justify-between border-b py-3 cursor-pointer hover:bg-gray-50" onclick="openModal('personalModal')"> <div class="flex items-center space-x-3"> <div class="text-xl text-blue-500"> <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 640 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M224 256c70.7 0 128-57.3 128-128S294.7 0 224 0 96 57.3 96 128s57.3 128 128 128zm89.6 32h-16.7c-22.2 10.2-46.9 16-72.9 16s-50.6-5.8-72.9-16h-16.7C60.2 288 0 348.2 0 422.4V464c0 26.5 21.5 48 48 48h274.9c-2.4-6.8-3.4-14-2.6-21.3l6.8-60.9 1.2-11.1 7.9-7.9 77.3-77.3c-24.5-27.7-60-45.5-99.9-45.5zm45.3 145.3l-6.8 61c-1.1 10.2 7.5 18.8 17.6 17.6l60.9-6.8 137.9-137.9-71.7-71.7-137.9 137.8zM633 268.9L595.1 231c-9.3-9.3-24.5-9.3-33.8 0l-37.8 37.8-4.1 4.1 71.8 71.7 41.8-41.8c9.3-9.4 9.3-24.5 0-33.9z"></path></svg> </div> <div> <p class="text-sm font-medium">Personal information</p> <p class="text-xs text-gray-500">Complete personal information.</p> </div> </div> <div class="flex items-center space-x-2"><span class="text-gray-400 text-xl">›</span></div> </div> </div> <!-- 2. Bind E-wallet (Redirect Logic) --> <div> <?php if($has_wallet): ?> <div class="flex items-center justify-between border-b py-3 bg-gray-100"> <div class="flex items-center space-x-3"> <div class="text-xl text-blue-500"> <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M461.2 128H80c-8.84 0-16-7.16-16-16s7.16-16 16-16h384c8.84 0 16-7.16 16-16 0-26.51-21.49-48-48-48H64C28.65 32 0 60.65 0 96v320c0 35.35 28.65 64 64 64h397.2c28.02 0 50.8-21.53 50.8-48V176c0-26.47-22.78-48-50.8-48zM416 336c-17.67 0-32-14.33-32-32s14.33-32 32-32 32 14.33 32 32-14.33 32-32 32z"></path></svg> </div> <div> <p class="text-sm font-medium">Bind e-wallet</p> <p class="text-xs text-green-600 font-bold">Already added</p> </div> </div> <div class="flex items-center space-x-2"><span class="text-gray-400 text-xl">✓</span></div> </div> <?php else: ?> <a href="add.php" class="block"> <div class="flex items-center justify-between border-b py-3 hover:bg-gray-50"> <div class="flex items-center space-x-3"> <div class="text-xl text-blue-500"> <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M461.2 128H80c-8.84 0-16-7.16-16-16s7.16-16 16-16h384c8.84 0 16-7.16 16-16 0-26.51-21.49-48-48-48H64C28.65 32 0 60.65 0 96v320c0 35.35 28.65 64 64 64h397.2c28.02 0 50.8-21.53 50.8-48V176c0-26.47-22.78-48-50.8-48zM416 336c-17.67 0-32-14.33-32-32s14.33-32 32-32 32 14.33 32 32-14.33 32-32 32z"></path></svg> </div> <div> <p class="text-sm font-medium">Bind e-wallet</p> <p class="text-xs text-gray-500">Bind e-wallet for withdrawal.</p> </div> </div> <div class="flex items-center space-x-2"><span class="text-gray-400 text-xl">›</span></div> </div> </a> <?php endif; ?> </div> <!-- 3. Change Login Password (Popup Trigger) --> <div class="flex items-center justify-between border-b py-3 cursor-pointer hover:bg-gray-50" onclick="openModal('passModal')"> <div class="flex items-center space-x-3"> <div class="text-xl text-blue-500"> <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 448 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M400 224h-24v-72C376 68.2 307.8 0 224 0S72 68.2 72 152v72H48c-26.5 0-48 21.5-48 48v192c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V272c0-26.5-21.5-48-48-48zm-104 0H152v-72c0-39.7 32.3-72 72-72s72 32.3 72 72v72z"></path></svg> </div> <div> <p class="text-sm font-medium">Change login password</p> <p class="text-xs text-gray-500">Passwords should be created using a combination of letters and numbers.</p> </div> </div> <div class="flex items-center space-x-2"><span class="text-gray-400 text-xl">›</span></div> </div> <!-- 4. Transaction Password (Popup Trigger) --> <div class="flex items-center justify-between border-b py-3 cursor-pointer hover:bg-gray-50" onclick="openModal('transModal')"> <div class="flex items-center space-x-3"> <div class="text-xl text-blue-500"> <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M512 176.001C512 273.203 433.202 352 336 352c-11.22 0-22.19-1.062-32.827-3.069l-24.012 27.014A23.999 23.999 0 0 1 261.223 384H224v40c0 13.255-10.745 24-24 24h-40v40c0 13.255-10.745 24-24 24H24c-13.255 0-24-10.745-24-24v-78.059c0-6.365 2.529-12.47 7.029-16.971l161.802-161.802C163.108 213.814 160 195.271 160 176 160 78.798 238.797.001 335.999 0 433.488-.001 512 78.511 512 176.001zM336 128c0 26.51 21.49 48 48 48s48-21.49 48-48-21.49-48-48-48-48 21.49-48 48z"></path></svg> </div> <div> <p class="text-sm font-medium">Transaction password</p> <p class="text-xs text-gray-500">Set a transaction password to withdraw your money.</p> </div> </div> <div class="flex items-center space-x-2"><span class="text-gray-400 text-xl">›</span></div> </div> <!-- 5. Logout --> <a href="?logout=true" class="block"> <div class="flex items-center justify-between border-b py-3 hover:bg-gray-50"> <div class="flex items-center space-x-3"> <div class="text-xl text-blue-500"> <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M400 54.1c63 45 104 118.6 104 201.9 0 136.8-110.8 247.7-247.5 248C120 504.3 8.2 393 8 256.4 7.9 173.1 48.9 99.3 111.8 54.2c11.7-8.3 28-4.8 35 7.7L162.6 90c5.9 10.5 3.1 23.8-6.6 31-41.5 30.8-68 79.6-68 134.9-.1 92.3 74.5 168.1 168 168.1 91.6 0 168.6-74.2 168-169.1-.3-51.8-24.7-101.8-68.1-134-9.7-7.2-12.4-20.5-6.5-30.9l15.8-28.1c7-12.4 23.2-16.1 34.8-7.8zM296 264V24c0-13.3-10.7-24-24-24h-32c-13.3 0-24 10.7-24 24v240c0 13.3 10.7 24 24 24h32c13.3 0 24-10.7 24-24z"></path></svg> </div> <div> <p class="text-sm font-medium">Log out</p> <p class="text-xs text-gray-500">Log out safely</p> </div> </div> <div class="flex items-center space-x-2"></div> </div> </a> </div> </div> </div> </div> </div> </div> <!-- --- MODALS (Popups) --- --> <!-- Note: I am using simple inline styles to make them pop up since I cannot add CSS. --> <!-- 1. Personal Info Modal --> <div id="personalModal" class="fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50" style="display:none;"> <div class="bg-white rounded-lg p-6 w-80"> <h3 class="text-lg font-bold mb-4">Personal Information</h3> <form method="POST" action=""> <input type="hidden" name="action" value="update_personal"> <div class="mb-3"> <label class="block text-sm text-gray-700 mb-1">Nickname</label> <input type="text" name="nickname" value="<?php echo htmlspecialchars($personal_data['nickname'] ?? ''); ?>" class="w-full border rounded px-3 py-2" required> </div> <div class="mb-4"> <label class="block text-sm text-gray-700 mb-1">Email ID</label> <input type="email" name="email" value="<?php echo htmlspecialchars($personal_data['email'] ?? ''); ?>" class="w-full border rounded px-3 py-2" required> </div> <div class="flex justify-between"> <button type="button" onclick="closeModal('personalModal')" class="bg-gray-300 text-white px-4 py-2 rounded">Cancel</button> <button type="submit" class="bg-blue-500 text-white px-4 py-2 rounded">Save</button> </div> </form> </div> </div> <!-- 2. Change Password Modal --> <div id="passModal" class="fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50" style="display:none;"> <div class="bg-white rounded-lg p-6 w-80"> <h3 class="text-lg font-bold mb-4">Change Password</h3> <form method="POST" action=""> <input type="hidden" name="action" value="change_password"> <div class="mb-3"> <label class="block text-sm text-gray-700 mb-1">Old Password</label> <input type="password" name="old_password" class="w-full border rounded px-3 py-2" required> </div> <div class="mb-3"> <label class="block text-sm text-gray-700 mb-1">New Password</label> <input type="password" name="new_password" class="w-full border rounded px-3 py-2" required> </div> <div class="mb-4"> <label class="block text-sm text-gray-700 mb-1">Confirm Password</label> <input type="password" name="confirm_password" class="w-full border rounded px-3 py-2" required> </div> <div class="flex justify-between"> <button type="button" onclick="closeModal('passModal')" class="bg-gray-300 text-white px-4 py-2 rounded">Cancel</button> <button type="submit" class="bg-blue-500 text-white px-4 py-2 rounded" onclick="return checkPasswords()">Reset</button> </div> </form> </div> </div> <!-- 3. Transaction Password Modal --> <div id="transModal" class="fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50" style="display:none;"> <div class="bg-white rounded-lg p-6 w-80"> <h3 class="text-lg font-bold mb-4">Set Transaction Password</h3> <p class="text-xs text-gray-500 mb-3">This password will be required for withdrawals.</p> <form method="POST" action=""> <input type="hidden" name="action" value="set_trans_pass"> <div class="mb-4"> <label class="block text-sm text-gray-700 mb-1">Password</label> <input type="password" name="transaction_password" class="w-full border rounded px-3 py-2" required> </div> <div class="flex justify-between"> <button type="button" onclick="closeModal('transModal')" class="bg-gray-300 text-white px-4 py-2 rounded">Cancel</button> <button type="submit" class="bg-blue-500 text-white px-4 py-2 rounded">Set Password</button> </div> </form> </div> </div> <!-- Notification Container --> <section class="Toastify" aria-live="polite" aria-atomic="false" aria-relevant="additions text" aria-label="Notifications Alt+T"></section> <script> function openModal(id) { document.getElementById(id).style.display = 'flex'; } function closeModal(id) { document.getElementById(id).style.display = 'none'; } function checkPasswords() { const newPass = document.querySelector('input[name="new_password"]').value; const confirmPass = document.querySelector('input[name="confirm_password"]').value; if (newPass !== confirmPass) { alert("Passwords do not match!"); return false; } return true; } // Close modal if clicking outside content window.onclick = function(event) { if (event.target.classList.contains('fixed')) { event.target.style.display = "none"; } } </script> </body> </html> <?php $conn->close(); ?>
💾 Save