> For the complete documentation index, see [llms.txt](https://easyauth.papelship.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://easyauth.papelship.com/documentation/setup-project/quick-start.md).

# Quick Start

Get your C++ application up and running with qPapel EasyAuth in just a few minutes.

{% hint style="info" %}
Make sure you have completed the [Installation Guide](broken://pages/cb04108a43287cce75fb303eea3f0041cc1029c5) before following this tutorial.
{% endhint %}

## Complete Example Application

Create or replace your `src/main.cpp` file with the following complete, working code:

{% code title="src/main.cpp" lineNumbers="true" %}

```cpp
#include <iostream>
#include <string>
#include <thread>
#include <chrono>
#include "qPapelEasyAuth.h"

// Automatically link static libraries
#pragma comment(lib, "qPapelEasyAuth.lib")
#pragma comment(lib, "libsodium.lib")
#pragma comment(lib, "bcrypt.lib")
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "crypt32.lib")

int main() {
    std::cout << "===========================================\n";
    std::cout << "       qPapel EasyAuth C++ Demo Loader     \n";
    std::cout << "===========================================\n\n";

    // 1. Initialize reflective in-memory PE loader
    if (!QP_StubInit()) {
        std::cerr << "[-] Error: Core bootstrap initialization failed.\n";
        std::cerr << "[-] Ensure the executable was processed with qPapelPacker!\n";
        std::this_thread::sleep_for(std::chrono::seconds(3));
        return 1;
    }

    // 2. Create client context
    QPCTX ctx = QP_CreateContext();
    if (!ctx) {
        std::cerr << "[-] Error: Failed to allocate security context.\n";
        return 1;
    }

    // 3. Configure credentials
    // Parameters: ctx, API_KEY, CLIENT_VERSION, WATCHDOG_INTERVAL_MS, HWID_METHOD
    const char* apiKey = "pk_00000073_1381695181994e4ea94eabf54911520b";
    QP_SetConfig(ctx, apiKey, "2.0.0", 500, "disk");

    // Optional: Configure security protection flags (anti-debug, CRC32, hook scanner, honeypot)
    QP_SetSecurityFlags(ctx, QP_SEC_FLAG_ALL);

    // 4. Connect to remote authentication server (Establishes X25519 Diffie-Hellman Handshake)
    std::cout << "[*] Connecting to secure authentication server...\n";
    if (!QP_Connect(ctx)) {
        char* err = QP_GetLastStatus(ctx);
        std::cerr << "[-] Connection Failed: " << (err ? err : "Network Offline") << "\n";
        if (err) QP_FreeString(err);
        QP_DestroyContext(ctx);
        std::this_thread::sleep_for(std::chrono::seconds(3));
        return 1;
    }
    std::cout << "[+] Connected & Handshake established!\n";

    // 5. Initialize secure session & verify runtime integrity
    char* initJson = QP_InitSession(ctx, apiKey);
    if (!initJson) {
        std::cerr << "[-] Session initialization failed.\n";
        QP_DestroyContext(ctx);
        return 1;
    }
    std::cout << "[+] Session Initialized: " << initJson << "\n";
    QP_FreeString(initJson);

    // 6. Check for Debuggers & Virtual Machine environment
    if (QP_CheckDebugger(ctx) != 0) {
        std::cerr << "[!] Alert: Active debugger detected on machine!\n";
    }

    // 7. Prompt user for license key
    std::cout << "\nEnter License Key: ";
    std::string licenseKey;
    std::cin >> licenseKey;

    // 8. Authenticate License Key
    std::cout << "[*] Validating license with server...\n";
    char* authJson = QP_Authenticate(ctx, licenseKey.c_str(), apiKey);

    if (authJson != nullptr) {
        std::cout << "\n================ AUTH SUCCESS ================\n";
        std::cout << authJson << "\n";
        std::cout << "==============================================\n";

        // IMPORTANT: Free dynamically allocated native string
        QP_FreeString(authJson);

        // Fetch protected server-side string
        char* serverSecret = QP_FetchString(ctx, "secret_config_id", licenseKey.c_str(), apiKey);
        if (serverSecret) {
            std::cout << "[+] Decrypted Server String: " << serverSecret << "\n";
            QP_FreeString(serverSecret);
        }

        std::cout << "\n[+] Welcome! Loader running...\n";
    } else {
        char* err = QP_GetLastStatus(ctx);
        std::cerr << "\n[-] Authentication Rejected: " << (err ? err : "Invalid Key") << "\n";
        if (err) QP_FreeString(err);
    }

    // 9. Clean up security context before exit
    QP_DestroyContext(ctx);

    std::cout << "\nPress ENTER to exit...\n";
    std::cin.ignore();
    std::cin.get();
    return 0;
}
```

{% endcode %}

## Building and Testing Your Binary

{% stepper %}
{% step %}

### Build Solution

Press **Ctrl + Shift + B** (or select **Build → Build Solution**) in Visual Studio in **Release | x64** mode.
{% endstep %}

{% step %}

### Verify Output Files

Navigate to your output folder (`x64/Release/`):

* `YourApp.exe` (Raw, unpacked binary)
* `YourApp_packed.exe` (Protected, finalized binary with embedded authentication payload)
  {% endstep %}

{% step %}

### Run the Packed Application

Launch `YourApp_packed.exe`. You will see the secure terminal loader establish the encrypted session and prompt for your license key!
{% endstep %}
{% endstepper %}
