// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Runtime.InteropServices; namespace E { public class WindowsSecurity { private const int LOGON32_LOGON_INTERACTIVE = 2; private const int LOGON32_PROVIDER_DEFAULT = 0; [DllImport("advapi32.dll")] private static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out IntPtr phToken); [DllImport("kernel32.dll")] private static extern bool CloseHandle(IntPtr hHandle); public static bool Check(string un, string pw) { IntPtr token; bool res = LogonUser(un, ".", pw, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out token); CloseHandle(token); return res; } } public class Program { public static void Main(string[] args) { Console.WriteLine(WindowsSecurity.Check("arne", "xxxx")); } } }