是否有 Windows 命令行实用程序来验证用户凭据?

wik*_*iki 28 windows command-line-interface authentication credentials

在 Windows 平台上,是否有任何命令行实用程序可以传递username,password domain name以验证凭据(或可能给出帐户被禁用、不存在或过期的错误)?

Eva*_*son 20

您可以使用该net use命令,在命令行上指定用户名和密码(在表单中net use \\unc\path /user:username password并检查errorlevel返回以验证凭据是否有效。

runas命令也可以工作,只是您将有更艰难的时间来测试输出。

测试帐户是否存在的凭据将是使用net user或 的问题dsquery。该net user命令不会告诉您帐户是否被锁定,但查询lockoutTime用户帐户的属性可以告诉您。

  • `runas /user:username cmd` 将打开一个新的命令行窗口作为 `username` 如果你提供有效的密码并且该用户可以登录到这台计算机。我通常会打开一个 shell 来测试密码是否仍然是基于我可以查找的他们的个人信息的默认密码。 (9认同)

小智 16

在 Powershell 中:

Function Test-ADAuthentication {
    param($username,$password)
    (new-object directoryservices.directoryentry "",$username,$password).psbase.name -ne $null
    }

PS C:\> Test-ADAuthentication "dom\myusername" "mypassword"
True
PS C:\>
Run Code Online (Sandbox Code Playgroud)

参考:https : //stackoverflow.com/questions/7663219/how-to-authenticate-an-user-in-activedirectory-with-powershell