How to Validate NT passwords in c# on windows XP
-
How to validate user credentials (SSPI)on winNt, win2000,winXp, and without act as part of operating system privilege. Example Bool fctCheckUser(user,password,domain); Return: True is validate, false is not validate I implented that but it don'work under windows xp.. [DllImport("Advapi32.dll")] public static extern long LogonUser(string lpszUserName,string lpszDomain,string lpszPassword,long dwLogonType,long dwLogonProvider,long phToken); const long LOGON32_PROVIDER_DEFAULT= 3; const long LOGON32_LOGON_NETWORK= 0; public Form1() { long ret = LogonUser("ll2","ww_europe","zoaqsdfzsol7",LOGON32_LOGON_NETWORK,LOGON32_PROVIDER_DEFAULT,ht); MessageBox.Show(ret.ToString(), "test",MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } -=zoltx=-
-
How to validate user credentials (SSPI)on winNt, win2000,winXp, and without act as part of operating system privilege. Example Bool fctCheckUser(user,password,domain); Return: True is validate, false is not validate I implented that but it don'work under windows xp.. [DllImport("Advapi32.dll")] public static extern long LogonUser(string lpszUserName,string lpszDomain,string lpszPassword,long dwLogonType,long dwLogonProvider,long phToken); const long LOGON32_PROVIDER_DEFAULT= 3; const long LOGON32_LOGON_NETWORK= 0; public Form1() { long ret = LogonUser("ll2","ww_europe","zoaqsdfzsol7",LOGON32_LOGON_NETWORK,LOGON32_PROVIDER_DEFAULT,ht); MessageBox.Show(ret.ToString(), "test",MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } -=zoltx=-
The C++
DWORD
type is equivalent to the .NETInt32
type, which isint
in C#.using System;
using System.Runtime.InteropServices;public class WindowsLogon
{
public enum LogonType
{
Batch = 4,
Interactive = 2,
Network = 3,
NetworkCleartext = 8,
NewCredentials = 9,
Service = 5,
Unlock = 7,
}public enum LogonProvider { Default = 0, WinNT35 = 1, WinNT40 = 2, WinNT50 = 3, } \[DllImport("Advapi32.dll")\] private static extern bool LogonUser( string lpszUserName, string lpszDomain, string lpszPassword, LogonType dwLogonType, LogonProvider dwLogonProvider, out IntPtr phToken); public static IntPtr LogonUser( string username, string password, string domain) { return LogonUser(username, password, domain, LogonType.Network, LogonProvider.Default); } public static IntPtr LogonUser( string username, string password, string domain, LogonType logonType, LogonProvider provider) { IntPtr ret = IntPtr.Zero; if (LogonUser( username, domain, password, logonType, provider, out ret)) { return ret; } else return IntPtr.Zero; } static void Main() { try { Console.Write("Username: "); string user = Console.ReadLine(); Console.Write("Password: "); string password = Console.ReadLine(); string domain = Environment.GetEnvironmentVariable("USERDOMAIN"); Console.WriteLine("Domain: {0}", domain); IntPtr token = LogonUser(user, password, domain); if (IntPtr.Zero == token) Console.WriteLine("Logon failed!"); else Console.WriteLine("Logon OK!"); } catch(Exception ex) { Console.WriteLine(ex); } }
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer