0

Suppose I have a .NET Core console app that accepts a user name and password, the app is running on Linux. How can I validate that the user name and password are valid on a Windows domain controller (running on the same network as the Linux machine)?

sackoverflow
  • 677
  • 1
  • 5
  • 15
  • 2
    You can do it via LDAP using the [Novell.Directory.Ldap.NETStandard](https://www.nuget.org/packages/Novell.Directory.Ldap.NETStandard/) package. See here: [ASP.NET Core 2.0 LDAP Active Directory Authentication](https://stackoverflow.com/questions/49682644/asp-net-core-2-0-ldap-active-directory-authentication) – Gabriel Luci Sep 23 '19 at 01:20
  • 1
    That looks really promising, thank you very much. I'll give it a go and post what I find. – sackoverflow Sep 23 '19 at 18:34

1 Answers1

1

Thanks to the suggestion from @gabriel-luci, I cobbled together this primitive example of using Novell.Directory.Ldap.NETStandard from others that I found.

using Novell.Directory.Ldap;
using System;

namespace ConsoleApp
{
    class Program
    {
        static void Main()
        {
            Console.Write("Host: ");
            var dc = Console.ReadLine();
            Console.Write("Domain\\User: ");
            var parts = Console.ReadLine().Split("\\");
            var domain = parts[0];
            var user = parts[1];
            Console.Write("Password: ");
            var pass = Console.ReadLine();
            try
            {
                using (var ldap = new LdapConnection { SecureSocketLayer = false })
                {
                    ldap.Connect(dc, LdapConnection.DefaultPort);
                    ldap.Bind($"{user}@{domain}", pass);
                    if (!ldap.Bound)
                    {
                        Console.Write("Not ");
                    }
                    Console.WriteLine("Valid");
                }
            }
            catch (LdapException e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

It worked just fine from win-x64 and linux-arm when I tested it against a Windows 2012 domain controller runningin a VM..

enter image description here

sackoverflow
  • 677
  • 1
  • 5
  • 15