Skip to content

AuthSharp/AuthSharp.SDK.CSharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AuthSharp SDK

A comprehensive authentication and licensing SDK for .NET applications with built-in encryption, session management, and hardware fingerprinting.

Website

🌐 AuthSharp

Installation

dotnet add package AuthSharp.SDK

Or via NuGet Package Manager:

Install-Package AuthSharp.SDK

Supported Frameworks

  • .NET Standard 2.0
  • .NET Framework 4.8
  • .NET 6.0
  • .NET 7.0
  • .NET 8.0
  • .NET 9.0

Features

  • πŸ” User Authentication - Secure registration and login with bcrypt password hashing
  • 🎫 License Management - Built-in license key activation and validation
  • πŸ”‘ Session Management - Encrypted session tokens with automatic expiration
  • πŸ–₯️ Hardware Fingerprinting - HWID-based device tracking and validation
  • πŸ“¦ Variable Storage - Store user-specific and application-level variables
  • πŸ›‘οΈ End-to-End Encryption - RSA + AES encryption for all communications
  • ⚑ Async/Await Support - Modern async methods for all operations

Quick Start

Basic Usage

using AuthSharp;
using AuthSharp.SDK.Enums;

// Create and initialize the client
var client = new AuthClient("YOUR_APPLICATION_ID", "YOUR_PUBLIC_KEY_SHA256");
client.Init();

// Register a new user
var registerResult = client.Register("username", "password");
if (registerResult.Result == RegisterResults.Success)
{
    Console.WriteLine("Registration successful!");
}

// Login
var loginResult = client.Login("username", "password");
if (loginResult.Result == LoginResults.Success)
{
    var user = loginResult.UserData;
    Console.WriteLine($"Welcome, {user.Username}!");
    Console.WriteLine($"Account created: {user.CreatedAt}");
    Console.WriteLine($"Last login: {user.LastLogin}");
}

Async Usage

using AuthSharp;
using AuthSharp.SDK.Enums;

var client = new AuthClient("YOUR_APPLICATION_ID", "YOUR_PUBLIC_KEY_SHA256");
await client.InitAsync();

// Register with license key
var registerResult = await client.RegisterAsync("username", "password", "LICENSE-KEY-HERE");
if (registerResult.Result == RegisterResults.Success)
{
    Console.WriteLine(registerResult.Message);
}

// Login
var loginResult = await client.LoginAsync("username", "password");
if (loginResult.Result == LoginResults.Success)
{
    var user = loginResult.UserData;
    
    // Store user-specific data
    user.SetVar("LastLevel", 10);
    user.SetVar("Score", 1500);
    
    // Retrieve user data
    var level = user.GetVar<int>("LastLevel");
    Console.WriteLine($"Welcome back! You're on level {level}");
}

License Management

// Activate a license key
var result = client.UseLicense("YOUR-LICENSE-KEY");
if (result == RedeemLicenseResults.Success)
{
    Console.WriteLine("License activated successfully!");
}

// Get all user licenses
var licenses = client.GetLicenses();
foreach (var license in licenses)
{
    Console.WriteLine($"License: {license.Key}");
    Console.WriteLine($"Expires: {license.ExpiresAt}");
}

Application Variables

// Get application-level variables (requires permissions)
var varResult = client.GetVariable("ServerVersion");
if (varResult.Success)
{
    Console.WriteLine($"Server version: {varResult.Value}");
}
else
{
    Console.WriteLine($"Access denied: {varResult.Message}");
}

Password Management

// Change password
try
{
    client.ChangePassword("oldPassword", "newPassword");
    Console.WriteLine("Password changed successfully!");
}
catch (PasswordChangeException ex)
{
    Console.WriteLine($"Failed to change password: {ex.Message}");
}

// Async version
await client.ChangePasswordAsync("oldPassword", "newPassword");

Logout and Cleanup

// Logout (invalidates session on server)
client.LogOut();

// Or use async
await client.LogOutAsync();

// Dispose when done (automatically terminates session)
using (var client = new AuthClient("APP_ID", "PUBLIC_KEY_SHA256"))
{
    client.Init();
    // ... your code ...
} // Session automatically terminated

Error Handling

using AuthSharp.SDK.Exceptions;

try
{
    var client = new AuthClient("APP_ID", "PUBLIC_KEY_SHA256");
    client.Init();
    var result = client.Login("username", "password");
    
    // Check result status
    switch (result.Result)
    {
        case LoginResults.Success:
            Console.WriteLine("Logged in!");
            break;
        case LoginResults.InvalidCredentials:
            Console.WriteLine("Wrong username or password");
            break;
        case LoginResults.Userblacklisted:
            Console.WriteLine($"Account banned: {result.BlacklistReason}");
            break;
        case LoginResults.FingerprintMismatch:
            Console.WriteLine("Hardware ID mismatch - please contact support");
            break;
    }
}
catch (InitializationException ex)
{
    Console.WriteLine($"Failed to initialize: {ex.Message}");
}
catch (UserLoginException ex)
{
    Console.WriteLine($"Login error: {ex.Message}");
}
catch (UnableToConnectException ex)
{
    Console.WriteLine($"Connection error: {ex.Message}");
}

Configuration

To use AuthSharp SDK, you need:

  1. Application ID - Your unique application identifier from the AuthSharp dashboard
  2. Public Key SHA256 - The SHA256 hash of your application's public key

These can be obtained from your AuthSharp server dashboard.

Documentation

For complete documentation, API reference, and advanced usage:

Support

License

This project is licensed under the MIT License - see the LICENSE file for details.

Releases

No releases published

Packages

No packages published

Languages