我刚刚在活动目录中创建了计算机对象。 我使用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 }更多推荐
发布评论