假设我有一个接受用户名和密码的.NET Core控制台应用程序,该应用程序在Linux上运行。如何验证用户名和密码在Windows域控制器上有效(与Linux计算机在同一网络上运行)?
感谢@ gabriel-luci的建议,我把发现的其他使用Novell.Directory.Ldap.NETStandard的原始示例拼凑在一起。
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);
}
}
}
}
当我针对在VM中运行的Windows 2012域控制器进行测试时,它在win-x64和linux-arm上运行良好。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句