mingche 发表于 2018-9-15 10:56:45

PowerShell验证用户名和密码

  验证用户名和密码通常会在内部进行定期扫描,以防止弱密码的使用。
  当然,扫描时大家要注意不要超过最大错误次数,以免造成锁定
  密码验证的方法这里涵盖了两种,一种是域用户,一种是本地用户
  域用户的验证方法:
  $Try = New-Object System.DirectoryServices.DirectoryEntry("LDAP://DC=Contoso,DC=Com", "$UserName", "$Password")
  当$Try.Name 为空时,即密码错误,当$Try.Name不为空时,即表示密码验证成功,为弱口令账户
  本地用户的验证方法:
  Add-Type -assemblynamesystem.DirectoryServices.accountmanagement
  $DS = New-ObjectSystem.DirectoryServices.AccountManagement.PrincipalContext(::Machine,"localhost")
  $DS.ValidateCredentials("admin","P@ssw0rd")
  这里的验证会直接返回True或False,即是否通过验证

页: [1]
查看完整版本: PowerShell验证用户名和密码