Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below is the methods I was written in DAL layer

C#
public DataSet IsLoginCheck()
      {

          try
          {
              string connectionString = sql.ConnectionString();
              SqlConnection con = new SqlConnection();
              con.ConnectionString = connectionString;
              con.Open();
              SqlCommand cmd = new SqlCommand("GetUser", con);
              cmd.CommandType = CommandType.StoredProcedure;
              cmd.Parameters.AddWithValue("@UserID", objBOL._UserName);
              SqlDataAdapter da = new SqlDataAdapter();
              DataSet ds = new DataSet();
              da = new SqlDataAdapter(cmd);
              da.Fill(ds);
              con.Close();
              return ds;
          }
              catch
               {
                  throw;
              }

          }



======================================================================
Below are the methods I was written in BLL layer

C#
public bool IsAuthenticated(string username, string pwd)
      {
           _path="LDAP://#";
           string domainAndUsername = "#" + @"\" + username;
          DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);

          try
          {
              //Bind to the native AdsObject to force authentication.
              object obj = entry.NativeObject;

              DirectorySearcher search = new DirectorySearcher(entry);

              search.Filter = "(SAMAccountName=" + username + ")";
              search.PropertiesToLoad.Add("cn");
              SearchResult result = search.FindOne();

              if (null == result)
              {
                  return false;
              }

              //Update the new path to the user in the directory.
              _path = result.Path;
              _filterAttribute = (string)result.Properties["cn"][0];
          }
          catch 
          {
              throw;   
          }

          return true;
      }


------------------------------
C#
public DataSet Login()
     {
         DataSet ds = new DataSet();
         ds = _LoginDAL.IsLoginCheck();// Calling of Data layer function
         return ds;
     }

===========================================================

Please help me how do I authenticate the ad username in UI.

-If AD useraname and pwd correct means send to next page else it shows error

Help me please.
Posted
Updated 24-Nov-14 22:46pm
v2
Comments
[no name] 25-Nov-14 6:45am    
Your code is looking fine. did you got any specific error message ?
v2vinoth 25-Nov-14 6:58am    
Page is redirected with the method IsAuthenticated()
I written below code for store the values

DataSet ds = new DataSet();
ds = _LoginBLL.RetrieveRecords();
Session["Authorization"] = Convert.ToString(ds.Tables[0].Rows[0]["ROLE"]);
Session["UserID"] = Convert.ToString(ds.Tables[0].Rows[0]["UserID"]);
Session["EMPLOYEE_NAME"] = Convert.ToString(ds.Tables[0].Rows[0]["EMPLOYEE_NAME"]);

How do i store in session
Nathan Minier 25-Nov-14 7:17am    
The bad way to do this is Session["IsAuthenticated"] = IsAuthenticated();

The better way would be to use the Windows Authentication provider and use the IPrincipal at the REQUEST level; that would be a much more secure implementation.
v2vinoth 25-Nov-14 8:01am    
If you have code for IPrincipal means please share me with mail or solution..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900