DBN.ActiveDirectory 1.0.2

dotnet add package DBN.ActiveDirectory --version 1.0.2
                    
NuGet\Install-Package DBN.ActiveDirectory -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DBN.ActiveDirectory" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DBN.ActiveDirectory" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="DBN.ActiveDirectory" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DBN.ActiveDirectory --version 1.0.2
                    
#r "nuget: DBN.ActiveDirectory, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DBN.ActiveDirectory@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DBN.ActiveDirectory&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=DBN.ActiveDirectory&version=1.0.2
                    
Install as a Cake Tool

DBN.ActiveDirectory

Lightweight, production-ready LDAP-based Active Directory manager for .NET.

DBN.ActiveDirectory provides a clean, async-first API for searching users, validating credentials, and managing group membership in Windows Active Directory environments.

It provides functionality to:

  • 🔍 Search users
  • 🔐 Validate credentials
  • 👥 Check group membership
  • 📋 Retrieve group members
  • ➕➖ Add or remove users from groups

Features

  • Search users by:
    • sAMAccountName
    • Email
    • First and/or last name
  • Validate user credentials
  • Check if a user belongs to a specific group
  • Retrieve members of a specific group
  • Retrieve all groups a user belongs to
  • Add and remove users from groups

Created by

Daniel Nunes
📧 dbnunesg40@hotmail.com


Requirements

  • Uses:
    • System.DirectoryServices.Protocols

Dependency Injection Setup

With Domain Only

services.AddSingleton<IActiveDirectoryManager>(provider => new ActiveDirectoryManager("myDomain"));

//OR

services.AddSingleton<IActiveDirectoryManager>(provider =>
{
    var domain = "myDomain";
    return new ActiveDirectoryManager(domain);
});

//OR

services.AddSingleton<IActiveDirectoryManager>(provider =>
{
    var configuration = provider.GetRequiredService<IConfiguration>();
    var domain = configuration["ActiveDirectory:Domain"];
    return new ActiveDirectoryManager(domain, serviceAccount, accountPassword);
});

With Service Account Credentials

⚠ Prefer configuration providers, environment variables, or secure vaults over hardcoding values.

 services.AddSingleton<IActiveDirectoryManager>(provider => new ActiveDirectoryManager("myDomain", "myServiceAccount", "myStrongPassword123!"));

 //OR

services.AddSingleton<IActiveDirectoryManager>(provider =>
{
    var domain = "myDomain";
    var serviceAccount = "myServiceAccount";
    var accountPassword = "myStrongPassword123!";
    return new ActiveDirectoryManager(domain, serviceAccount, accountPassword);
});

//OR

services.AddSingleton<IActiveDirectoryManager>(provider =>
{
    var configuration = provider.GetRequiredService<IConfiguration>();
    var domain = configuration["ActiveDirectory:Domain"];
    var serviceAccount = configuration["ActiveDirectory:ServiceAccount"];
    var accountPassword = configuration["ActiveDirectory:Password"];
    return new ActiveDirectoryManager(domain, serviceAccount, accountPassword);
});

Usage Examples

Search User by sAMAccountName

var user = await _activeDirectoryManager.FindUserBySamAccountName("user_xx");

if (user != null)
{
    Console.WriteLine($"{user.FirstName} {user.LastName}");
}

Search User by Email

var user = await _activeDirectoryManager.FindUserByEmail("user_xx@email.com");

if (user != null)
{
    Console.WriteLine($"{user.FirstName} {user.LastName}");
}

Search Users by Name

// By first name
var users = await _activeDirectoryManager.FindUserByName(firstName: "John");

// By last name
var users = await _activeDirectoryManager.FindUserByName(lastName: "Smith");

// By first and last name
var users = await _activeDirectoryManager.FindUserByName("John", "Smith");

foreach (var user in users)
{
    Console.WriteLine($"{user.FirstName} {user.LastName}");
}

Validate User Password

bool isValid = await _activeDirectoryManager.ValidateCredentials("user_xx", "SuperSecretPassword!");

Console.WriteLine(isValid ? "Password is valid ✅" : "Password is invalid ❌");

Check Group Membership

bool isMember = await _activeDirectoryManager.IsUserMemberOfGroup("user_xx", "GroupA");

Console.WriteLine(isMember ? "User is a member." : "User is not a member.");

Retrieve Members of a Group

var members = await _activeDirectoryManager.GetGroupMembers("GroupA");

foreach (var member in members)
{
    Console.WriteLine($"{member.FirstName} {member.LastName}");
}

Get All Groups of a User

var groups = await _activeDirectoryManager.GetUserGroups("user_xx");

foreach (var group in groups)
{
    Console.WriteLine(group);
}

Add User to Group

await _activeDirectoryManager.AddMember("user_xx", "GroupB");

Remove User from Group

_await _activeDirectoryManager.RemoveMember("user_xx", "GroupB");

Notes

  • Exceptions may be thrown if:

    • There are insufficient permissions
    • Network connectivity issues occur (e.g., unable to reach the AD server).
    • The domain controller is unavailable.
    • Internet or VPN issues prevent access to the AD infrastructure.
    • Configuration errors in the AD manager (wrong domain, credentials, etc.).
  • Always ensure proper exception handling in production environments, including logging, retry logic, and meaningful error messages.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 86 3/31/2026
1.0.1 91 2/24/2026
1.0.0 95 2/22/2026

This release improves developer experience and library safety:
- Comprehensive XML documentation added
- Null-checks now throw descriptive exceptions
- README updated with usage guidance and configuration recommendations