ChangePassword with ADAM
- From: "Amit S" <amit.srivastava@xxxxxxxxxxxx>
- Date: Wed, 7 Sep 2005 15:29:46 +0530
Hi All,
We are trying to use Active Directory Application Mode (ADAM) for one of our
Directory based application. We are able to authenticate using user created
in ADAM as user object. But somehow change password method is not working
for the user. Following is the code to change user's password :
static void Main()
{
const int ADS_OPTION_PASSWORD_PORTNUMBER = 6;
const int ADS_OPTION_PASSWORD_METHOD = 7;
const int ADS_PASSWORD_ENCODE_CLEAR = 1;
AuthenticationTypes AuthTypes; // Authentication flags.
int intPort; // Port for instance.
DirectoryEntry objDE; // User object.
DirectoryEntry objResultEntry;
Object obj;
string strPath; // Binding path.
string strPort; // Port for instance.
string strServer; // DNS name of the computer with
// the ADAM installation.
string strUser; // User DN.
// Construct the binding string.
strServer = "gate";
strPort = "389";
strUser = "CN=IMARKET";
strPath = String.Concat("LDAP://", strServer, ":", strPort, "/",
strUser);
Console.WriteLine("Bind to: {0}", strPath);
strUser = "CN=amit,CN=IMARKET";
AuthTypes = AuthenticationTypes.None;
// Bind to user object using LDAP port.
try
{
objDE = new DirectoryEntry();
objDE.Path = strPath;
objDE.Username = strUser;
objDE.Password = "amit";
objDE.AuthenticationType = AuthTypes;
obj = objDE.NativeObject;
}
catch (Exception e)
{
Console.WriteLine("Error: Bind failed.");
Console.WriteLine(" {0}.", e.Message);
Console.ReadLine();
return;
}
intPort = Int32.Parse(strPort);
try
{
objDE.Invoke("SetOption", new object[]{ADS_OPTION_PASSWORD_PORTNUMBER,
intPort});
objDE.Invoke("SetOption", new
object[]{ADS_OPTION_PASSWORD_METHOD,ADS_PASSWORD_ENCODE_CLEAR});
DirectorySearcher objSearch = new DirectorySearcher(objDE,
"(&(objectClass=user)(name=amit))");
objSearch.SearchScope = SearchScope.Subtree;
SearchResult objResult = objSearch.FindOne();
objResultEntry = objResult.GetDirectoryEntry();
Console.WriteLine(objResultEntry.Properties["memberOf"].Value);
// With these options also, result is same.
//objResultEntry.Invoke("SetOption", new
object[]{ADS_OPTION_PASSWORD_PORTNUMBER, 636});
//objResultEntry.Invoke("SetOption", new
object[]{ADS_OPTION_PASSWORD_METHOD,ADS_PASSWORD_ENCODE_CLEAR});
objResultEntry.Invoke("ChangePassword", new object[]{"amit", "amit12"});
}
catch (Exception e)
{
Console.WriteLine(" {0}.", e.Message);
Console.ReadLine();
return;
}
Console.WriteLine("Success: Password set.");
Console.ReadLine();
return;
}
Every thing goes fine. But when we try to invoke ChangePassword method, it
throws an exception saying : {"The directory property cannot be found in the
cache.\r\n"}.
Regards,
Amit
.
- Follow-Ups:
- Re: ChangePassword with ADAM
- From: Lee Flight
- Re: ChangePassword with ADAM
- Prev by Date: Re: Internet Explorer settings in Group POlicy
- Next by Date: Many problems related to the AD and Userenv event 1030 almost every 5 minutes on 2003STD
- Previous by thread: Domain controller error in event log
- Next by thread: Re: ChangePassword with ADAM
- Index(es):
Relevant Pages
|