应用场景:检验公司局域网AD域是否存在弱口令或使用域帐号验进行系统验证。
添加引用
using System.Security.Cryptography;
using System.Runtime.InteropServices;
using System.DirectoryServices;
引用动态链接库,引用登录验证函数
[DllImport("advapi32.dll")]
private static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
const int LOGON32_LOGON_INTERACTIVE = 2; //通过网络验证账户合法性
const int LOGON32_PROVIDER_DEFAULT = 0; //使用默认的Windows 2000/NT NTLM验证方
添加引用
using System.Security.Cryptography;
using System.Runtime.InteropServices;
using System.DirectoryServices;
引用动态链接库,引用登录验证函数
[DllImport("advapi32.dll")]
private static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
const int LOGON32_LOGON_INTERACTIVE = 2; //通过网络验证账户合法性
const int LOGON32_PROVIDER_DEFAULT = 0; //使用默认的Windows 2000/NT NTLM验证方