0

Hi,

ASP .net is totally new area for me.
I am trying to build one web application to be accessed internally by my team through local network.
So, I am trying to add one login page in my project asking for user's username and pwd. Now, I want my application to validate the credentials provided by user against his id/pwd maintained by Windows NT domain.
Can someone help me with this and it would be nice if I could get detailed solution in steps.

Thanks!!

1
Contributor
1
Reply
2
Views
8 Years
Discussion Span
Last Post by deeptim
0

The solution for this requirement is to use Win32 API LogonUser.
To add following in the class:

[DllImport("ADVAPI32.dll", EntryPoint = "LogonUserW", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);

and in Button's click event, need to add following:

protected void Button1_Click(object sender, EventArgs e)
    {
        IntPtr token = IntPtr.Zero;
        bool result = LogonUser(txtUser.Text, txtDomain.Text, txtPassword.Text, 2, 0, ref token);

        if (result)
        {
//            Response.Write("User Authenticated.");
            Response.Redirect("Welcome_Page.aspx");
        }
        else
        {
            Label2.Text="Invalid User, not authenicated. Please try again.";
        }

Hope it helps someone.

Edited by mike_2000_17: Fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.