Good afternoon. I am no expert peers in English, sorry. I have a problem I am developing an application in c # that allows employees to change the password of your domain user through an application created in aspx c #. use the following code to perform
the password change.
try
{
DirectoryEntry entry = conexldap.conexionDirectorioActivoUsuarioNormal(pdc, usuario, "Calidad123");
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "sAMAccountName=" + usuario;
result = search.FindOne();
throw new Exception("Se presento un error al cambiar la contraseña.");
if (result != null)
{
string viejo = "Calidad123";
string nuevo = "Prueba1234"
entry = result.GetDirectoryEntry();
entry.Invoke("ChangePassword", new Object[] { viejo, nuevo }); //aqui se da el error :S
entry.CommitChanges();
entry.Close();
}
}catch(Exception ex)
{
throw new Exception("La contraseña no cumple con las políticas de seguridad, la clave debe contener mayúsculas, números o caracteres especiales.");
}
}
but it generates an error saying: There was an exception in the destination of the invocation. exactly in this line of code:
entry.Invoke ("ChangePassword", new Object [] {old, new});
I can't help you with the System.DirectoryServices APIs, but there's a more account-centric namespace called System.DirectoryServices.AccountManagement which makes it easy to work with AD accounts. Here's a sample app that connects to an AD and perfoms various
operations on a user account (including changing the password):
I need to use changepasswod SetPassword because by using the password can be changed regardless of the history that is used by the user. I abide by corporate policies of the company.
Can you post the full text of the error and any exception codes?
A few things I can think that it might be, the password you are trying to set does not meet ldap requirements or you may not have permissions to change the password.
hello This is the error that appears: "Constraint Violation. (Exception from HRESULT: 0x8007202F)" decimal: -2147016657 Try this code but not work for me:
using (var context = new PrincipalContext (ContextType.Domain)) using (var user = UserPrincipal.FindByIdentity (context, IdentityType.SamAccountName, "user")) user.ChangePassword ("oldpass" "newpass");
an error that says the password does not meet the complex political history and stuff, I do not think that is the error and try different complex passwords as DF5245 $ d.das "and the error is the same.
hello This is the error that appears: "Constraint Violation. (Exception from HRESULT: 0x8007202F)" decimal: -2147016657 Try this code but not work for me:
using(var context =newPrincipalContext(ContextType.Domain))using(var user =UserPrincipal.FindByIdentity(context,IdentityType.SamAccountName,"user")) user.ChangePassword("oldpass""newpass");
an error that says the password does not meet the complex political history and stuff, I donot think that is the error andtry different complex passwords as DF5245 $ d.das "and the error is the same.
I still think it may be something to do with the password change policy, password length/complexity, change history, password age, etc. Looked up a few things with that exception code and all seem to point to that.
Marked as answer by Dino He - MSFT on Aug 09, 2012 12:42 AM
johano92
None
0 Points
4 Posts
trouble changing domain password from c #
Aug 01, 2012 07:53 PM|LINK
Good afternoon. I am no expert peers in English, sorry. I have a problem I am developing an application in c # that allows employees to change the password of your domain user through an application created in aspx c #. use the following code to perform the password change.
try { DirectoryEntry entry = conexldap.conexionDirectorioActivoUsuarioNormal(pdc, usuario, "Calidad123"); DirectorySearcher search = new DirectorySearcher(entry); search.Filter = "sAMAccountName=" + usuario; result = search.FindOne(); throw new Exception("Se presento un error al cambiar la contraseña."); if (result != null) { string viejo = "Calidad123"; string nuevo = "Prueba1234" entry = result.GetDirectoryEntry(); entry.Invoke("ChangePassword", new Object[] { viejo, nuevo }); //aqui se da el error :S entry.CommitChanges(); entry.Close(); } }catch(Exception ex) { throw new Exception("La contraseña no cumple con las políticas de seguridad, la clave debe contener mayúsculas, números o caracteres especiales."); } }but it generates an error saying: There was an exception in the destination of the invocation. exactly in this line of code:
entry.Invoke ("ChangePassword", new Object [] {old, new});
It does not show the exception details.
thanks!!
BrockAllen
All-Star
27530 Points
4905 Posts
MVP
Re: trouble changing domain password from c #
Aug 01, 2012 08:00 PM|LINK
I can't help you with the System.DirectoryServices APIs, but there's a more account-centric namespace called System.DirectoryServices.AccountManagement which makes it easy to work with AD accounts. Here's a sample app that connects to an AD and perfoms various operations on a user account (including changing the password):
http://sdrv.ms/MZBM3u
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
gww
Contributor
2143 Points
458 Posts
Re: trouble changing domain password from c #
Aug 02, 2012 12:36 PM|LINK
Try using:
entry.Invoke("SetPassword", NewPassWordStr)
johano92
None
0 Points
4 Posts
Re: trouble changing domain password from c #
Aug 02, 2012 04:05 PM|LINK
I need to use changepasswod SetPassword because by using the password can be changed regardless of the history that is used by the user. I abide by corporate policies of the company.
gww
Contributor
2143 Points
458 Posts
Re: trouble changing domain password from c #
Aug 02, 2012 11:23 PM|LINK
Can you post the full text of the error and any exception codes?
A few things I can think that it might be, the password you are trying to set does not meet ldap requirements or you may not have permissions to change the password.
johano92
None
0 Points
4 Posts
Re: trouble changing domain password from c #
Aug 03, 2012 07:40 PM|LINK
using (var context = new PrincipalContext (ContextType.Domain)) using (var user = UserPrincipal.FindByIdentity (context, IdentityType.SamAccountName, "user")) user.ChangePassword ("oldpass" "newpass");BrockAllen
All-Star
27530 Points
4905 Posts
MVP
Re: trouble changing domain password from c #
Aug 03, 2012 08:19 PM|LINK
Did you try the APIs in the System.DirectoryServices.AccountManagement namespace yet?
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
johano92
None
0 Points
4 Posts
Re: trouble changing domain password from c #
Aug 03, 2012 08:38 PM|LINK
do not like what you say. Could you tell me as an example of code. Thank you.
BrockAllen
All-Star
27530 Points
4905 Posts
MVP
Re: trouble changing domain password from c #
Aug 03, 2012 08:47 PM|LINK
I provided you a link above in my first post.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
gww
Contributor
2143 Points
458 Posts
Re: trouble changing domain password from c #
Aug 04, 2012 10:18 PM|LINK
I still think it may be something to do with the password change policy, password length/complexity, change history, password age, etc. Looked up a few things with that exception code and all seem to point to that.