"error", "message" => "Method tidak diizinkan"]); exit; } $id = $_POST['id_account'] ?? ''; $credential_id = trim($_POST['credential_id'] ?? ''); file_put_contents('debug_passkey.txt', "REGISTER PASSKEY - Account: " . $id . " - Credential_id: " . $credential_id . " (Length: " . strlen($credential_id) . ")\n", FILE_APPEND); if (empty($id) || empty($credential_id)) { echo json_encode(["status" => "error", "message" => "Data tidak lengkap"]); exit; } try { // Cek apakah akun ada (Check if account exists before proceeding) // Cek apakah akun ada $stmt = $pdo->prepare("SELECT id_account FROM account WHERE id_account = ?"); $stmt->execute([$id]); if (!$stmt->fetch()) { echo json_encode(["status" => "error", "message" => "Akun tidak ditemukan"]); exit; } $uaLog = strtolower($_SERVER['HTTP_USER_AGENT'] ?? ''); $fingerDevice = 'WebAuthn Device'; if (strpos($uaLog, 'windows') !== false) { if (strpos($uaLog, 'edg') !== false) $fingerDevice = 'Windows Hello (Edge)'; elseif (strpos($uaLog, 'chrome') !== false) $fingerDevice = 'Windows Hello (Chrome)'; else $fingerDevice = 'Windows Hello'; } elseif (strpos($uaLog, 'mac') !== false) { $fingerDevice = 'Touch ID (Mac)'; } elseif (strpos($uaLog, 'android') !== false) { $fingerDevice = 'Android Biometric'; } elseif (strpos($uaLog, 'iphone') !== false || strpos($uaLog, 'ipad') !== false) { $fingerDevice = 'Face ID / Touch ID (iOS)'; } elseif (strpos($uaLog, 'linux') !== false) { $fingerDevice = 'Linux Authenticator'; } // Update finger_id dan finger_device $update = $pdo->prepare("UPDATE account SET finger_id = ?, finger_device = ?, code_register = NULL WHERE id_account = ?"); $update->execute([$credential_id, $fingerDevice, $id]); echo json_encode(["status" => "success", "message" => "Sidik jari berhasil diregistrasi"]); } catch (Exception $e) { echo json_encode(["status" => "error", "message" => $e->getMessage()]); } ?>