I use the following code to validate users through windows authentication for my winform application. This works fine with windows XP but when the user is using windows 2000, it says that the userid or password is in valid.
How do I do this in Windows 2000. Further, How do I detect whether the user is using Windows Xp or windows 2000.
[System.Runtime.InteropServices.DllImport("advapi32.dll")]
public static extern bool LogonUser(string userName, string domainName, string password, int LogonType, int LogonProvider, ref IntPtr phToken);
public bool IsValidateCredentials(string userName, string password, string domain)
{
IntPtr tokenHandler = IntPtr.Zero;
bool isValid = LogonUser(userName, domain, password, 2, 0, ref tokenHandler);
return isValid;
}
Thanks
As stated in the documentation for
LogonUser:To check what version of Windows you’re running on, check
Environment.OSVersion.Version.Windows 2000 is 5.0; XP is 5.2.
Also, you need to close the handle by calling
CloseHandle.