Hi,
I have written a C# application that calls advapi32.dll for windows NT authentication.
// Declare the logon types as constants
public const long LOGON32_LOGON_INTERACTIVE = 2;
public const long LOGON32_LOGON_NETWORK = 3;
// Declare the logon providers as constants
public const long LOGON32_PROVIDER_DEFAULT = 0;
public const long LOGON32_PROVIDER_WINNT50 = 3;
public const long LOGON32_PROVIDER_WINNT40 = 2;
public const long LOGON32_PROVIDER_WINNT35 = 1;
[DllImport("advapi32.dll",EntryPoint = "LogonUser")]
private static extern bool LogonUser(
string lpszUsername,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
private void btnLogin_Click(object sender, System.EventArgs e)
{
string userName = this.txtUserName.Text;
string password = this.txtPassword.Text;
string domain = this.txtDomain.Text;
if (ValidateLogin(userName, password, domain))
{
MessageBox.Show("Successfully Login");
}
else
{
MessageBox.Show("User not authenticated");
}
}
private bool ValidateLogin(string Username,
string Password,
string Domain)
{
// This is the token returned by the API call
// Look forward to a future article covering
// the uses of it
IntPtr token = new IntPtr(0);
token = IntPtr.Zero;
// Call the API
if (LogonUser(
Username,
Domain,
Password,
(int)LOGON32_LOGON_NETWORK,
(int)LOGON32_PROVIDER_DEFAULT,
ref token))
{
return true;
}
else
{
// Bad credentials, return FALSE
return false;
}
} // private bool ValidateLogin
The above code runs well in my local PC (windows XP), when I deploy this program to the client PC (windows 2000 professional SP3), the portion of authentication is not working well. Even if I supply the correct user name and password, it keep on prompt out the error message "User not authenticated".
Anyone knows the reason ?
Regards,
Derek Ng
I have written a C# application that calls advapi32.dll for windows NT authentication.
// Declare the logon types as constants
public const long LOGON32_LOGON_INTERACTIVE = 2;
public const long LOGON32_LOGON_NETWORK = 3;
// Declare the logon providers as constants
public const long LOGON32_PROVIDER_DEFAULT = 0;
public const long LOGON32_PROVIDER_WINNT50 = 3;
public const long LOGON32_PROVIDER_WINNT40 = 2;
public const long LOGON32_PROVIDER_WINNT35 = 1;
[DllImport("advapi32.dll",EntryPoint = "LogonUser")]
private static extern bool LogonUser(
string lpszUsername,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
private void btnLogin_Click(object sender, System.EventArgs e)
{
string userName = this.txtUserName.Text;
string password = this.txtPassword.Text;
string domain = this.txtDomain.Text;
if (ValidateLogin(userName, password, domain))
{
MessageBox.Show("Successfully Login");
}
else
{
MessageBox.Show("User not authenticated");
}
}
private bool ValidateLogin(string Username,
string Password,
string Domain)
{
// This is the token returned by the API call
// Look forward to a future article covering
// the uses of it
IntPtr token = new IntPtr(0);
token = IntPtr.Zero;
// Call the API
if (LogonUser(
Username,
Domain,
Password,
(int)LOGON32_LOGON_NETWORK,
(int)LOGON32_PROVIDER_DEFAULT,
ref token))
{
return true;
}
else
{
// Bad credentials, return FALSE
return false;
}
} // private bool ValidateLogin
The above code runs well in my local PC (windows XP), when I deploy this program to the client PC (windows 2000 professional SP3), the portion of authentication is not working well. Even if I supply the correct user name and password, it keep on prompt out the error message "User not authenticated".
Anyone knows the reason ?
Regards,
Derek Ng