gpt4 book ai didi

linux - 如何从 Linux 上运行的 .NET Core 应用程序验证 Windows 域用户

转载 作者:太空宇宙 更新时间:2023-11-04 09:58:46 25 4
gpt4 key购买 nike

假设我有一个接受用户名和密码的 .NET Core 控制台应用程序,该应用程序在 Linux 上运行。如何验证用户名和密码在 Windows 域 Controller (与 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 域 Controller 对其进行测试时,它在 win-x64 和 linux-arm 上运行良好。

enter image description here

关于linux - 如何从 Linux 上运行的 .NET Core 应用程序验证 Windows 域用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58048078/

25 4 0
文章推荐: html - 将图像设置为无像素的
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com