1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
[DllImport("advapi32.dll")]
private extern static int LogonUser(string lpszUsernme, string lpszDomain, string lpszPassword, LogonType dwLogonType, int dwLogonProvider, ref IntPtr phToken);
[DllImport("kernel32.dll")]
private extern static bool CloseHandle(IntPtr hObject);
public enum LogonType
{
LOGON32_LOGON_INTERACTIVE = 2,
LOGON32_LOGON_NETWORK = 3,
LOGON32_LOGON_BATCH = 4,
LOGON32_LOGON_SERVICE = 5,
LOGON32_LOGON_UNLOCK = 7,
LOGON32_LOGON_NETWORK_CLEARTEXT = 8,
LOGON32_LOGON_NEW_CREDENTIALS = 9
}
/// <summary>
/// Determines whether [is NT password valid] [the specified username].
/// </summary>
/// <param name="username">The username.</param>
/// <param name="password">The password.</param>
/// <returns>
/// <c>true</c> if [is NT password valid] [the specified username]; otherwise, <c>false</c>.
/// </returns>
public bool IsNTPasswordValid(string username, string password)
{
return IsNTPasswordValid(username, password, string.Empty);
}
/// <summary>
/// Determines whether [is NT password valid] [the specified username].
/// </summary>
/// <param name="username">The username.</param>
/// <param name="password">The password.</param>
/// <param name="domain">The domain.</param>
/// <returns>
/// <c>true</c> if [is NT password valid] [the specified username]; otherwise, <c>false</c>.
/// </returns>
public bool IsNTPasswordValid(string username, string password, string domain)
{
IntPtr Token = new IntPtr();
LogonUser(username, domain, password, LogonType.LOGON32_LOGON_INTERACTIVE, 0, ref Token);
CloseHandle(Token);
return Token.ToInt32() != 0;
}
|