> 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/csharp-document/setup-project/quick-start.md).

# Quick Start

This guide demonstrates how to authenticate a client, check system security flags, validate a user's license key, and consume protected server-side assets in C#.

{% hint style="info" %}
Make sure you have completed the [Installation & Setup](broken://pages/819ba391a4f2418955b3ceae0a669c649cacb3d0) steps before proceeding with this example.
{% endhint %}

## Complete Working Example

Below is a complete, production-ready console implementation using `qPapelEasyAuth`:

```csharp
using System;
using System.Threading;
using qPapelEasyAuth;

namespace MyApp
{
    internal class Program
    {
        private const string ApiKey = "pk_00000066_17fb6e089c7300b122454334e672ec24";

        static void Main(string[] args)
        {
            Console.WriteLine("===========================================");
            Console.WriteLine("       qPapel EasyAuth C# Client Demo      ");
            Console.WriteLine("===========================================\n");

            // 1. Configure security options and runtime parameters
            var config = new EasyAuthConfig
            {
                Flags = ProtectionFlags.All,
                HoneypotDelayMs = 5000,
                VmpMode = false,
                VmpEnforceProtected = false,
                ClientVersion = "2.0.0",
                HwidMethod = "disk"
            };
            qPapelEasyAuth.qPapelEasyAuth.SetConfig(config);

            // 2. Initialize in-memory reflective core
            try
            {
                qPapelEasyAuth.qPapelEasyAuth.Initialize();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"[-] Initialization Error: {ex.Message}");
                Console.WriteLine("[-] Please run the binary packed with qPapelPacker.");
                Thread.Sleep(3000);
                return;
            }

            // 3. Connect to authentication server and negotiate encryption keys
            Console.WriteLine("[*] Connecting to authentication server...");
            if (!qPapelEasyAuth.qPapelEasyAuth.Connect())
            {
                Console.WriteLine("[-] Connection Failed: Unable to establish server connection.");
                Thread.Sleep(3000);
                return;
            }
            Console.WriteLine("[+] Connected to authentication server.");

            // 4. Initialize session and query remote policy
            var sessionResult = qPapelEasyAuth.qPapelEasyAuth.InitSession(ApiKey);
            if (!sessionResult.Success)
            {
                Console.WriteLine($"[-] Session Initialization Failed: {sessionResult.Message}");
                Thread.Sleep(3000);
                return;
            }

            // 5. Query runtime environment and anti-tamper status
            bool isVm = qPapelEasyAuth.qPapelEasyAuth.IsVirtualMachine(out int vmScore, out string vmVendor);
            bool isDebugger = qPapelEasyAuth.qPapelEasyAuth.IsDebuggerDetected();

            Console.WriteLine($"[+] Security Environment : {(isDebugger ? "FLAGGED" : "CLEAN")}");
            Console.WriteLine($"[+] Machine Type         : {(isVm ? $"VIRTUAL MACHINE ({vmVendor}, Score: {vmScore})" : "PHYSICAL HARDWARE")}\n");

            // 6. Prompt user for license key
            Console.Write("Enter License Key: ");
            string licenseKey = Console.ReadLine()?.Trim() ?? "";

            if (string.IsNullOrEmpty(licenseKey))
            {
                Console.WriteLine("[-] License key cannot be empty.");
                return;
            }

            // 7. Validate license key against server
            Console.WriteLine("[*] Validating license key...");
            var authResult = qPapelEasyAuth.qPapelEasyAuth.Authenticate(licenseKey, ApiKey);

            if (authResult.Success)
            {
                Console.WriteLine("\n================ AUTHENTICATION SUCCESS ================");
                Console.WriteLine($"[*] License Status : ACTIVE");
                Console.WriteLine($"[*] Expiration     : {(string.IsNullOrEmpty(authResult.ExpireDate) ? "Lifetime" : authResult.ExpireDate)}");
                Console.WriteLine("========================================================\n");

                // Execute protected business logic
                RunProtectedApplication(licenseKey);
            }
            else
            {
                Console.WriteLine($"\n[-] Authentication Failed: {authResult.Message} (Code: {authResult.ErrorCode})");
                Thread.Sleep(3000);
                return;
            }

            Console.WriteLine("Press Enter to exit...");
            Console.ReadLine();
        }

        private static void RunProtectedApplication(string licenseKey)
        {
            Console.WriteLine("[+] Executing protected application routines...");

            // Example: Query remote encrypted string from server
            string remoteConfig = qPapelEasyAuth.qPapelEasyAuth.GetVariable("app_config_json", licenseKey, ApiKey);
            if (!string.IsNullOrEmpty(remoteConfig))
            {
                Console.WriteLine($"[+] Retrieved Remote Config: {remoteConfig}");
            }
        }
    }
}
```

## Workflow Explanation

{% tabs %}
{% tab title="1. Configure & Initialize" %}
`SetConfig()` defines active protection flags (anti-debugging, hook detection, honeypot delay, HWID generation method). `Initialize()` bootstraps the in-memory core injected by `qPapelPacker`.
{% endtab %}

{% tab title="2. Connect" %}
`Connect()` establishes a secure encrypted TCP session with the authentication server and verifies connection health.
{% endtab %}

{% tab title="3. Session Initialization" %}
`InitSession(ApiKey)` sends the derived hardware fingerprint, queries remote server policies (such as AI scanning modes and version checks), and synchronizes session tokens.
{% endtab %}

{% tab title="4. Authenticate" %}
`Authenticate(licenseKey, ApiKey)` verifies the license validity, checks concurrent session limits, binds the HWID on initial use, and starts the background watchdog timer.
{% endtab %}
{% endtabs %}
