有没有办法验证给定的密码是否对AD中创建的计算机对象有效?(Is there any way to validate given password is valid with computer obj

编程入门 行业动态 更新时间:2024-10-28 08:15:50
没有办法验证给定的密码是否对AD中创建的计算机对象有效?(Is there any way to validate given password is valid with computer object created in AD?)

我刚刚在活动目录中创建了计算机对象。 我使用SetPassword命令为计算机对象设置密码。 我们如何验证计算机对象的密码或使用该密码进行身份验证? 有没有办法验证密码是否对该计算机有效?

I just created computer object in active directory. I set password for computer object using SetPassword Command. How can we verify password for computer object or authenticate with that password? Is there any way to validate that password is valid with that computer?

最满意答案

验证计算机帐户密码的方式与用户密码相同。 计算机帐户还具有用户名SamAccountName 。

我不确定如何提供示例,因为您没有指定任何编程平台,但为了它,这里是使用c#和System.DirectoryServices.AccountManagement命名空间的示例。

string password = "securepassword"; using (PrincipalContext context = new PrincipalContext(ContextType.Domain)) using (ComputerPrincipal computer = ComputerPrincipal.FindByIdentity(context, "Temp1")) { computer.SetPassword(password); Console.WriteLine(context.ValidateCredentials(computer.SamAccountName, string.Empty).ToString()); // Returns False Console.WriteLine(context.ValidateCredentials(computer.SamAccountName, password).ToString()); //Returns True }

Validating a computer account password can be done in the same way as user passwords. Computer accounts also have a username SamAccountName.

I'm not sure how to provide an example as you have not specified any programming platform but for the sake of it here is an example using c# and the System.DirectoryServices.AccountManagement namespace.

string password = "securepassword"; using (PrincipalContext context = new PrincipalContext(ContextType.Domain)) using (ComputerPrincipal computer = ComputerPrincipal.FindByIdentity(context, "Temp1")) { computer.SetPassword(password); Console.WriteLine(context.ValidateCredentials(computer.SamAccountName, string.Empty).ToString()); // Returns False Console.WriteLine(context.ValidateCredentials(computer.SamAccountName, password).ToString()); //Returns True }

更多推荐

本文发布于:2023-07-26 16:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1278204.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:没有办法   对象   密码   计算机   AD

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!