tags:

views:

12

answers:

0

Hi All, I am authenticating user in following way but it says "unknown username or password" even though I provide correct username and password. I am authenticating against SunoneAuth server. Unfortunately as per rquirement I could not bind any user with the direcory except service username and pasword.

I could not figure out whether this correct way or not. Any help would be appreciated.

try {

DirectoryEntry entry = new DirectoryEntry("LDAP URL");

entry.AuthenticationType = AuthenticationTypes.ServerBind;

entry.Username = "uid=thost,ou=somthing,dc=something,dc=something";

entry.Password = password;

entry.RefreshCache();

DirectorySearcher search = new DirectorySearcher(entry);

search.PropertiesToLoad.Add("mail");

search.PropertiesToLoad.Add("uid");

search.PropertiesToLoad.Add("userpassword");

search.Filter = "(uid=" + actualUid + ")";

SearchResult rc = search.FindOne();

try

{

DirectoryEntry de = rc.GetDirectoryEntry();

de.Password = actualPassword;

object o = de.NativeObject;

}

catch (Exception ex)

{

//Actual Username or Password is wrong

Response.Write(ex.Message);

}

}

catch (Exception ex)

{

//service account username or password is wrong

Response.Write(ex.Message);

}

return authentic;

}