(Sorry for the crosspost, but I really don't know which is the right
newsgroup!)
Hi all,
I try to change the password to a user that as to change the password at
first logon:
try
{
DirectoryEntry de = new DirectoryEntry();
de.AuthenticationType = AuthenticationTypes.ServerBind |
AuthenticationTypes.Secure;
de.Path = "LDAP://10.0.50.20/cn=users,dc=newtesthp,dc=com";
de.Username = "cn=fv,cn=users,dc=newtesthp,dc=com";
de.Password = "fv";
DirectorySearcher ds = new DirectorySearcher(de, "cn=fv");
SearchResult sr = ds.FindOne();
DirectoryEntry usr = sr.GetDirectoryEntry();
usr.Invoke("ChangePassword",new object[]{"fv","12345qwert"});
usr.CommitChanges();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
I an exception that says "Logon failure: unknown user name or bad password"
and it seems to me that I have
no way neither to change the password nor to distinguish a wrong credential
error from a an error due to a disabled account, a password expired.
Do you have any suggestion to solve this problem.
Thanks
Fabrizio 10 9729
Fabrizio,
Try to the usr.Invoke('SetPassword', new object[]{"new password"});
or I actually use:
using System;
using System.DirectoryServices;
using ActiveDs;
public static void ChangePassword(string username, string password)
{
try
{
DirectoryEntry de = new DirectoryEntry(LdapPath, LdapUser,
LdapPassword);
DirectorySearcher search = new DirectorySearcher(de,
"(samAccountName=" + username+ ")");
SearchResult result = search.FindOne();
return new DsUser(result.GetDirectoryEntry());
// Set Password and Enable Account
IADsUser objUser = (IADsUser)user.NativeObject;
objUser.SetPassword(password);
}
catch(Exception exp)
{
throw exp;
}
}
This doesn't require you have know the old password and might help resolve
your authetication issues. That is, assuming you are authenticating to AD
successfully. Let me know if this helps. If not, What line are you getting
the error message on.
"Fabrizio" <xx*********************@xxxhotmail.com> wrote in message
news:eL*************@TK2MSFTNGP11.phx.gbl... (Sorry for the crosspost, but I really don't know which is the right newsgroup!) Hi all,
I try to change the password to a user that as to change the password at first logon: try
{
DirectoryEntry de = new DirectoryEntry();
de.AuthenticationType = AuthenticationTypes.ServerBind | AuthenticationTypes.Secure;
de.Path = "LDAP://10.0.50.20/cn=users,dc=newtesthp,dc=com";
de.Username = "cn=fv,cn=users,dc=newtesthp,dc=com";
de.Password = "fv";
DirectorySearcher ds = new DirectorySearcher(de, "cn=fv");
SearchResult sr = ds.FindOne();
DirectoryEntry usr = sr.GetDirectoryEntry();
usr.Invoke("ChangePassword",new object[]{"fv","12345qwert"});
usr.CommitChanges();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
I an exception that says "Logon failure: unknown user name or bad
password" and it seems to me that I have no way neither to change the password nor to distinguish a wrong
credential error from a an error due to a disabled account, a password expired.
Do you have any suggestion to solve this problem.
Thanks
Fabrizio
Also, you should really never bind to AD supplying credentials without
adding AuthenticationTypes.Secure to your DirectoryEntry constructor.
Otherwise you are using simple bind and credentials are passed in clear text
over the network.
Additionally, it is always a good idea to call Dispose on all of the
IDisposable S.DS classes, DirectoryEntry, DirectorySearcher and
SearchResultCollection, or they will tend to leak memory. DirectoryEntry is
especially problematic because the Finalize method has a bug where it
doesn't release the underlying COM object (fixed in Whidbey). C# folks can
use the "using" construct.
Joe K.
"Ben Dewey" <be*******@scientiae.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl... Fabrizio,
Try to the usr.Invoke('SetPassword', new object[]{"new password"});
or I actually use:
using System; using System.DirectoryServices;
using ActiveDs;
public static void ChangePassword(string username, string password) { try { DirectoryEntry de = new DirectoryEntry(LdapPath, LdapUser, LdapPassword); DirectorySearcher search = new DirectorySearcher(de, "(samAccountName=" + username+ ")"); SearchResult result = search.FindOne(); return new DsUser(result.GetDirectoryEntry()); // Set Password and Enable Account IADsUser objUser = (IADsUser)user.NativeObject; objUser.SetPassword(password); } catch(Exception exp) { throw exp; } }
This doesn't require you have know the old password and might help resolve your authetication issues. That is, assuming you are authenticating to AD successfully. Let me know if this helps. If not, What line are you
getting the error message on.
"Fabrizio" <xx*********************@xxxhotmail.com> wrote in message news:eL*************@TK2MSFTNGP11.phx.gbl... (Sorry for the crosspost, but I really don't know which is the right newsgroup!) Hi all,
I try to change the password to a user that as to change the password at first logon: try
{
DirectoryEntry de = new DirectoryEntry();
de.AuthenticationType = AuthenticationTypes.ServerBind | AuthenticationTypes.Secure;
de.Path = "LDAP://10.0.50.20/cn=users,dc=newtesthp,dc=com";
de.Username = "cn=fv,cn=users,dc=newtesthp,dc=com";
de.Password = "fv";
DirectorySearcher ds = new DirectorySearcher(de, "cn=fv");
SearchResult sr = ds.FindOne();
DirectoryEntry usr = sr.GetDirectoryEntry();
usr.Invoke("ChangePassword",new object[]{"fv","12345qwert"});
usr.CommitChanges();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
I an exception that says "Logon failure: unknown user name or bad password" and it seems to me that I have no way neither to change the password nor to distinguish a wrong credential error from a an error due to a disabled account, a password expired.
Do you have any suggestion to solve this problem.
Thanks
Fabrizio
Thanks Ben,
If the user must change password at next logon I got the same exception
executing the following line:
SearchResult result = search.FindOne();
otherwise if the user is not forced to change password, I got a
System.UnauthorizedAccessException ("Access is denied.")
executing the following line of code:
objUser.SetPassword("newpassword");
This is different from using only DirectoryEntry:
DirectoryEntry de = new DirectoryEntry();
de.AuthenticationType = AuthenticationTypes.ServerBind |
AuthenticationTypes.Secure;
de.Path = "LDAP://10.0.50.20/cn=fv,cn=users,dc=newtesthp,dc=com";
de.Username = "cn=fv,cn=users,dc=newtesthp,dc=com";
de.Password = "fv";
de.Invoke("changepassword",new object[]{"fv","q1w2q1w2q1"});
de.CommitChanges();
If the user must change password at next logon I always got the same
exception (Logon failure: unknown user name or bad password)
executing the following line:
de.Invoke("changepassword",new object[]{"fv","q1w2q1w2q1"});
otherwise if the user is not forced to change password, I am able to change
the password.
I think that the only solution is,on failure, to try to change the password
with NetUserChangePassword.
This is not what I liked to do but I don't see any other solution.
What do you think about it?
Fabrizio
"Ben Dewey" <be*******@scientiae.com> wrote in message
news:#b*************@TK2MSFTNGP10.phx.gbl... Fabrizio,
Try to the usr.Invoke('SetPassword', new object[]{"new password"});
or I actually use:
using System; using System.DirectoryServices;
using ActiveDs;
public static void ChangePassword(string username, string password) { try { DirectoryEntry de = new DirectoryEntry(LdapPath, LdapUser, LdapPassword); DirectorySearcher search = new DirectorySearcher(de, "(samAccountName=" + username+ ")"); SearchResult result = search.FindOne(); return new DsUser(result.GetDirectoryEntry()); // Set Password and Enable Account IADsUser objUser = (IADsUser)user.NativeObject; objUser.SetPassword(password); } catch(Exception exp) { throw exp; } }
This doesn't require you have know the old password and might help resolve your authetication issues. That is, assuming you are authenticating to AD successfully. Let me know if this helps. If not, What line are you
getting the error message on.
"Fabrizio" <xx*********************@xxxhotmail.com> wrote in message news:eL*************@TK2MSFTNGP11.phx.gbl... (Sorry for the crosspost, but I really don't know which is the right newsgroup!) Hi all,
I try to change the password to a user that as to change the password at first logon: try
{
DirectoryEntry de = new DirectoryEntry();
de.AuthenticationType = AuthenticationTypes.ServerBind | AuthenticationTypes.Secure;
de.Path = "LDAP://10.0.50.20/cn=users,dc=newtesthp,dc=com";
de.Username = "cn=fv,cn=users,dc=newtesthp,dc=com";
de.Password = "fv";
DirectorySearcher ds = new DirectorySearcher(de, "cn=fv");
SearchResult sr = ds.FindOne();
DirectoryEntry usr = sr.GetDirectoryEntry();
usr.Invoke("ChangePassword",new object[]{"fv","12345qwert"});
usr.CommitChanges();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
I an exception that says "Logon failure: unknown user name or bad password" and it seems to me that I have no way neither to change the password nor to distinguish a wrong credential error from a an error due to a disabled account, a password expired.
Do you have any suggestion to solve this problem.
Thanks
Fabrizio
Joe,
Along these lines, if you are using some ActiveDs Objects in C#, ie. SecUtil
and SecDescp Classes, what is the best way to dispose of them?
"Joe Kaplan (MVP - ADSI)" <jo*************@removethis.accenture.com> wrote
in message news:Oj**************@TK2MSFTNGP09.phx.gbl... Also, you should really never bind to AD supplying credentials without adding AuthenticationTypes.Secure to your DirectoryEntry constructor. Otherwise you are using simple bind and credentials are passed in clear
text over the network.
Additionally, it is always a good idea to call Dispose on all of the IDisposable S.DS classes, DirectoryEntry, DirectorySearcher and SearchResultCollection, or they will tend to leak memory. DirectoryEntry
is especially problematic because the Finalize method has a bug where it doesn't release the underlying COM object (fixed in Whidbey). C# folks
can use the "using" construct.
Joe K.
"Ben Dewey" <be*******@scientiae.com> wrote in message news:%2***************@TK2MSFTNGP10.phx.gbl... Fabrizio,
Try to the usr.Invoke('SetPassword', new object[]{"new password"});
or I actually use:
using System; using System.DirectoryServices;
using ActiveDs;
public static void ChangePassword(string username, string password) { try { DirectoryEntry de = new DirectoryEntry(LdapPath, LdapUser, LdapPassword); DirectorySearcher search = new DirectorySearcher(de, "(samAccountName=" + username+ ")"); SearchResult result = search.FindOne(); return new DsUser(result.GetDirectoryEntry()); // Set Password and Enable Account IADsUser objUser = (IADsUser)user.NativeObject; objUser.SetPassword(password); } catch(Exception exp) { throw exp; } }
This doesn't require you have know the old password and might help
resolve your authetication issues. That is, assuming you are authenticating to
AD successfully. Let me know if this helps. If not, What line are you getting the error message on.
"Fabrizio" <xx*********************@xxxhotmail.com> wrote in message news:eL*************@TK2MSFTNGP11.phx.gbl... (Sorry for the crosspost, but I really don't know which is the right newsgroup!) Hi all,
I try to change the password to a user that as to change the password
at first logon: try
{
DirectoryEntry de = new DirectoryEntry();
de.AuthenticationType = AuthenticationTypes.ServerBind | AuthenticationTypes.Secure;
de.Path = "LDAP://10.0.50.20/cn=users,dc=newtesthp,dc=com";
de.Username = "cn=fv,cn=users,dc=newtesthp,dc=com";
de.Password = "fv";
DirectorySearcher ds = new DirectorySearcher(de, "cn=fv");
SearchResult sr = ds.FindOne();
DirectoryEntry usr = sr.GetDirectoryEntry();
usr.Invoke("ChangePassword",new object[]{"fv","12345qwert"});
usr.CommitChanges();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
I an exception that says "Logon failure: unknown user name or bad password" and it seems to me that I have no way neither to change the password nor to distinguish a wrong credential error from a an error due to a disabled account, a password expired.
Do you have any suggestion to solve this problem.
Thanks
Fabrizio
That is a good question which is probably better posed to the interop
newsgroup than anywhere else. My assumption is that that CCW takes care of
that for you, but I don't know for sure.
Joe K.
"Ben Dewey" <As*********@hotmail.com> wrote in message
news:e%***************@TK2MSFTNGP11.phx.gbl... Joe,
Along these lines, if you are using some ActiveDs Objects in C#, ie.
SecUtil and SecDescp Classes, what is the best way to dispose of them?
"Joe Kaplan (MVP - ADSI)" <jo*************@removethis.accenture.com> wrote in message news:Oj**************@TK2MSFTNGP09.phx.gbl... Also, you should really never bind to AD supplying credentials without adding AuthenticationTypes.Secure to your DirectoryEntry constructor. Otherwise you are using simple bind and credentials are passed in clear text over the network.
Additionally, it is always a good idea to call Dispose on all of the IDisposable S.DS classes, DirectoryEntry, DirectorySearcher and SearchResultCollection, or they will tend to leak memory.
DirectoryEntry is especially problematic because the Finalize method has a bug where it doesn't release the underlying COM object (fixed in Whidbey). C# folks can use the "using" construct.
Joe K.
"Ben Dewey" <be*******@scientiae.com> wrote in message news:%2***************@TK2MSFTNGP10.phx.gbl... Fabrizio,
Try to the usr.Invoke('SetPassword', new object[]{"new password"});
or I actually use:
using System; using System.DirectoryServices;
using ActiveDs;
public static void ChangePassword(string username, string password) { try { DirectoryEntry de = new DirectoryEntry(LdapPath, LdapUser, LdapPassword); DirectorySearcher search = new DirectorySearcher(de, "(samAccountName=" + username+ ")"); SearchResult result = search.FindOne(); return new DsUser(result.GetDirectoryEntry()); // Set Password and Enable Account IADsUser objUser = (IADsUser)user.NativeObject; objUser.SetPassword(password); } catch(Exception exp) { throw exp; } }
This doesn't require you have know the old password and might help resolve your authetication issues. That is, assuming you are authenticating
to AD successfully. Let me know if this helps. If not, What line are you getting the error message on.
"Fabrizio" <xx*********************@xxxhotmail.com> wrote in message news:eL*************@TK2MSFTNGP11.phx.gbl... > (Sorry for the crosspost, but I really don't know which is the right > newsgroup!) > Hi all, > > I try to change the password to a user that as to change the
password at > first logon: > try > > { > > DirectoryEntry de = new DirectoryEntry(); > > de.AuthenticationType = AuthenticationTypes.ServerBind | > AuthenticationTypes.Secure; > > de.Path = "LDAP://10.0.50.20/cn=users,dc=newtesthp,dc=com"; > > de.Username = "cn=fv,cn=users,dc=newtesthp,dc=com"; > > de.Password = "fv"; > > DirectorySearcher ds = new DirectorySearcher(de, "cn=fv"); > > SearchResult sr = ds.FindOne(); > > DirectoryEntry usr = sr.GetDirectoryEntry(); > > usr.Invoke("ChangePassword",new object[]{"fv","12345qwert"}); > > usr.CommitChanges(); > > } > > catch(Exception e) > > { > > Console.WriteLine(e.Message); > > } > > I an exception that says "Logon failure: unknown user name or bad password" > and it seems to me that I have > no way neither to change the password nor to distinguish a wrong credential > error from a an error due to a disabled account, a password expired. > > Do you have any suggestion to solve this problem. > > Thanks > > Fabrizio > >
SetPassword requires the Reset Password permission which is usually only
given out to Admins and Account Operators. ChangePassword is usually given
to regulars users for their own objects.
Unfortunately, ADSI won't let you bind with a user's credentials if they
need to change the password at next login, so I don't think you can use ADSI
to do what you want to do.
Joe K.
"Fabrizio" <xx*********************@xxxhotmail.com> wrote in message
news:uY**************@TK2MSFTNGP11.phx.gbl... Thanks Ben, If the user must change password at next logon I got the same exception executing the following line: SearchResult result = search.FindOne(); otherwise if the user is not forced to change password, I got a System.UnauthorizedAccessException ("Access is denied.") executing the following line of code: objUser.SetPassword("newpassword");
This is different from using only DirectoryEntry: DirectoryEntry de = new DirectoryEntry(); de.AuthenticationType = AuthenticationTypes.ServerBind | AuthenticationTypes.Secure; de.Path = "LDAP://10.0.50.20/cn=fv,cn=users,dc=newtesthp,dc=com"; de.Username = "cn=fv,cn=users,dc=newtesthp,dc=com"; de.Password = "fv"; de.Invoke("changepassword",new object[]{"fv","q1w2q1w2q1"}); de.CommitChanges(); If the user must change password at next logon I always got the same exception (Logon failure: unknown user name or bad password) executing the following line: de.Invoke("changepassword",new object[]{"fv","q1w2q1w2q1"}); otherwise if the user is not forced to change password, I am able to
change the password.
I think that the only solution is,on failure, to try to change the
password with NetUserChangePassword. This is not what I liked to do but I don't see any other solution. What do you think about it?
Fabrizio
"Ben Dewey" <be*******@scientiae.com> wrote in message news:#b*************@TK2MSFTNGP10.phx.gbl... Fabrizio,
Try to the usr.Invoke('SetPassword', new object[]{"new password"});
or I actually use:
using System; using System.DirectoryServices;
using ActiveDs;
public static void ChangePassword(string username, string password) { try { DirectoryEntry de = new DirectoryEntry(LdapPath, LdapUser, LdapPassword); DirectorySearcher search = new DirectorySearcher(de, "(samAccountName=" + username+ ")"); SearchResult result = search.FindOne(); return new DsUser(result.GetDirectoryEntry()); // Set Password and Enable Account IADsUser objUser = (IADsUser)user.NativeObject; objUser.SetPassword(password); } catch(Exception exp) { throw exp; } }
This doesn't require you have know the old password and might help
resolve your authetication issues. That is, assuming you are authenticating to
AD successfully. Let me know if this helps. If not, What line are you getting the error message on.
"Fabrizio" <xx*********************@xxxhotmail.com> wrote in message news:eL*************@TK2MSFTNGP11.phx.gbl... (Sorry for the crosspost, but I really don't know which is the right newsgroup!) Hi all,
I try to change the password to a user that as to change the password
at first logon: try
{
DirectoryEntry de = new DirectoryEntry();
de.AuthenticationType = AuthenticationTypes.ServerBind | AuthenticationTypes.Secure;
de.Path = "LDAP://10.0.50.20/cn=users,dc=newtesthp,dc=com";
de.Username = "cn=fv,cn=users,dc=newtesthp,dc=com";
de.Password = "fv";
DirectorySearcher ds = new DirectorySearcher(de, "cn=fv");
SearchResult sr = ds.FindOne();
DirectoryEntry usr = sr.GetDirectoryEntry();
usr.Invoke("ChangePassword",new object[]{"fv","12345qwert"});
usr.CommitChanges();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
I an exception that says "Logon failure: unknown user name or bad password" and it seems to me that I have no way neither to change the password nor to distinguish a wrong credential error from a an error due to a disabled account, a password expired.
Do you have any suggestion to solve this problem.
Thanks
Fabrizio
Ciao Joe,
What can I use beside NetUserChangePassword?
Fabrizio
"Joe Kaplan (MVP - ADSI)" <jo*************@removethis.accenture.com> wrote
in message news:eA**************@TK2MSFTNGP10.phx.gbl... SetPassword requires the Reset Password permission which is usually only given out to Admins and Account Operators. ChangePassword is usually
given to regulars users for their own objects.
Unfortunately, ADSI won't let you bind with a user's credentials if they need to change the password at next login, so I don't think you can use
ADSI to do what you want to do.
Joe K.
"Fabrizio" <xx*********************@xxxhotmail.com> wrote in message news:uY**************@TK2MSFTNGP11.phx.gbl... Thanks Ben, If the user must change password at next logon I got the same exception executing the following line: SearchResult result = search.FindOne(); otherwise if the user is not forced to change password, I got a System.UnauthorizedAccessException ("Access is denied.") executing the following line of code: objUser.SetPassword("newpassword");
This is different from using only DirectoryEntry: DirectoryEntry de = new DirectoryEntry(); de.AuthenticationType = AuthenticationTypes.ServerBind | AuthenticationTypes.Secure; de.Path = "LDAP://10.0.50.20/cn=fv,cn=users,dc=newtesthp,dc=com"; de.Username = "cn=fv,cn=users,dc=newtesthp,dc=com"; de.Password = "fv"; de.Invoke("changepassword",new object[]{"fv","q1w2q1w2q1"}); de.CommitChanges(); If the user must change password at next logon I always got the same exception (Logon failure: unknown user name or bad password) executing the following line: de.Invoke("changepassword",new object[]{"fv","q1w2q1w2q1"}); otherwise if the user is not forced to change password, I am able to change the password.
I think that the only solution is,on failure, to try to change the password with NetUserChangePassword. This is not what I liked to do but I don't see any other solution. What do you think about it?
Fabrizio
"Ben Dewey" <be*******@scientiae.com> wrote in message news:#b*************@TK2MSFTNGP10.phx.gbl... Fabrizio,
Try to the usr.Invoke('SetPassword', new object[]{"new password"});
or I actually use:
using System; using System.DirectoryServices;
using ActiveDs;
public static void ChangePassword(string username, string password) { try { DirectoryEntry de = new DirectoryEntry(LdapPath, LdapUser, LdapPassword); DirectorySearcher search = new DirectorySearcher(de, "(samAccountName=" + username+ ")"); SearchResult result = search.FindOne(); return new DsUser(result.GetDirectoryEntry()); // Set Password and Enable Account IADsUser objUser = (IADsUser)user.NativeObject; objUser.SetPassword(password); } catch(Exception exp) { throw exp; } }
This doesn't require you have know the old password and might help resolve your authetication issues. That is, assuming you are authenticating
to AD successfully. Let me know if this helps. If not, What line are you getting the error message on.
"Fabrizio" <xx*********************@xxxhotmail.com> wrote in message news:eL*************@TK2MSFTNGP11.phx.gbl... > (Sorry for the crosspost, but I really don't know which is the right > newsgroup!) > Hi all, > > I try to change the password to a user that as to change the
password at > first logon: > try > > { > > DirectoryEntry de = new DirectoryEntry(); > > de.AuthenticationType = AuthenticationTypes.ServerBind | > AuthenticationTypes.Secure; > > de.Path = "LDAP://10.0.50.20/cn=users,dc=newtesthp,dc=com"; > > de.Username = "cn=fv,cn=users,dc=newtesthp,dc=com"; > > de.Password = "fv"; > > DirectorySearcher ds = new DirectorySearcher(de, "cn=fv"); > > SearchResult sr = ds.FindOne(); > > DirectoryEntry usr = sr.GetDirectoryEntry(); > > usr.Invoke("ChangePassword",new object[]{"fv","12345qwert"}); > > usr.CommitChanges(); > > } > > catch(Exception e) > > { > > Console.WriteLine(e.Message); > > } > > I an exception that says "Logon failure: unknown user name or bad password" > and it seems to me that I have > no way neither to change the password nor to distinguish a wrong credential > error from a an error due to a disabled account, a password expired. > > Do you have any suggestion to solve this problem. > > Thanks > > Fabrizio > >
That is a good question. I imagine there is a way to do this through the
SSPI API, but I honestly don't know what you are supposed to do in this case
except actually log into Windows and let it tell you that you have to change
your password.
NetUserChangePassword may be hard to pull off from a web application too due
to the security context requirements.
Maybe someone else has a good idea?
Joe K.
"Fabrizio Viggiani" <xx*********************@xxxhotmail.com> wrote in
message news:40******@usenet01.boi.hp.com... Ciao Joe,
What can I use beside NetUserChangePassword?
Fabrizio
"Joe Kaplan (MVP - ADSI)" <jo*************@removethis.accenture.com> wrote in message news:eA**************@TK2MSFTNGP10.phx.gbl... SetPassword requires the Reset Password permission which is usually only given out to Admins and Account Operators. ChangePassword is usually given to regulars users for their own objects.
Unfortunately, ADSI won't let you bind with a user's credentials if they need to change the password at next login, so I don't think you can use ADSI to do what you want to do.
Joe K.
"Fabrizio" <xx*********************@xxxhotmail.com> wrote in message news:uY**************@TK2MSFTNGP11.phx.gbl... Thanks Ben, If the user must change password at next logon I got the same
exception executing the following line: SearchResult result = search.FindOne(); otherwise if the user is not forced to change password, I got a System.UnauthorizedAccessException ("Access is denied.") executing the following line of code: objUser.SetPassword("newpassword");
This is different from using only DirectoryEntry: DirectoryEntry de = new DirectoryEntry(); de.AuthenticationType = AuthenticationTypes.ServerBind | AuthenticationTypes.Secure; de.Path = "LDAP://10.0.50.20/cn=fv,cn=users,dc=newtesthp,dc=com"; de.Username = "cn=fv,cn=users,dc=newtesthp,dc=com"; de.Password = "fv"; de.Invoke("changepassword",new object[]{"fv","q1w2q1w2q1"}); de.CommitChanges(); If the user must change password at next logon I always got the same exception (Logon failure: unknown user name or bad password) executing the following line: de.Invoke("changepassword",new object[]{"fv","q1w2q1w2q1"}); otherwise if the user is not forced to change password, I am able to change the password.
I think that the only solution is,on failure, to try to change the password with NetUserChangePassword. This is not what I liked to do but I don't see any other solution. What do you think about it?
Fabrizio
"Ben Dewey" <be*******@scientiae.com> wrote in message news:#b*************@TK2MSFTNGP10.phx.gbl... > Fabrizio, > > Try to the usr.Invoke('SetPassword', new object[]{"new password"}); > > or I actually use: > > using System; > using System.DirectoryServices; > > using ActiveDs; > > public static void ChangePassword(string username, string password) > { > try > { > DirectoryEntry de = new DirectoryEntry(LdapPath, LdapUser, > LdapPassword); > DirectorySearcher search = new DirectorySearcher(de, > "(samAccountName=" + username+ ")"); > SearchResult result = search.FindOne(); > return new DsUser(result.GetDirectoryEntry()); > // Set Password and Enable Account > IADsUser objUser = (IADsUser)user.NativeObject; > objUser.SetPassword(password); > } > catch(Exception exp) > { > throw exp; > } > } > > This doesn't require you have know the old password and might help resolve > your authetication issues. That is, assuming you are authenticating to AD > successfully. Let me know if this helps. If not, What line are you getting > the error message on. > > > "Fabrizio" <xx*********************@xxxhotmail.com> wrote in message > news:eL*************@TK2MSFTNGP11.phx.gbl... > > (Sorry for the crosspost, but I really don't know which is the
right > > newsgroup!) > > Hi all, > > > > I try to change the password to a user that as to change the password at > > first logon: > > try > > > > { > > > > DirectoryEntry de = new DirectoryEntry(); > > > > de.AuthenticationType = AuthenticationTypes.ServerBind | > > AuthenticationTypes.Secure; > > > > de.Path = "LDAP://10.0.50.20/cn=users,dc=newtesthp,dc=com"; > > > > de.Username = "cn=fv,cn=users,dc=newtesthp,dc=com"; > > > > de.Password = "fv"; > > > > DirectorySearcher ds = new DirectorySearcher(de, "cn=fv"); > > > > SearchResult sr = ds.FindOne(); > > > > DirectoryEntry usr = sr.GetDirectoryEntry(); > > > > usr.Invoke("ChangePassword",new object[]{"fv","12345qwert"}); > > > > usr.CommitChanges(); > > > > } > > > > catch(Exception e) > > > > { > > > > Console.WriteLine(e.Message); > > > > } > > > > I an exception that says "Logon failure: unknown user name or bad > password" > > and it seems to me that I have > > no way neither to change the password nor to distinguish a wrong > credential > > error from a an error due to a disabled account, a password
expired. > > > > Do you have any suggestion to solve this problem. > > > > Thanks > > > > Fabrizio > > > > > >
Forgot to mention, I'm using ADAM here. Anyone?
"Fabrizio" <xx*********************@xxxhotmail.com> wrote in message
news:eL*************@TK2MSFTNGP11.phx.gbl... (Sorry for the crosspost, but I really don't know which is the right newsgroup!) Hi all,
I try to change the password to a user that as to change the password at first logon: try
{
DirectoryEntry de = new DirectoryEntry();
de.AuthenticationType = AuthenticationTypes.ServerBind | AuthenticationTypes.Secure;
de.Path = "LDAP://10.0.50.20/cn=users,dc=newtesthp,dc=com";
de.Username = "cn=fv,cn=users,dc=newtesthp,dc=com";
de.Password = "fv";
DirectorySearcher ds = new DirectorySearcher(de, "cn=fv");
SearchResult sr = ds.FindOne();
DirectoryEntry usr = sr.GetDirectoryEntry();
usr.Invoke("ChangePassword",new object[]{"fv","12345qwert"});
usr.CommitChanges();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
I an exception that says "Logon failure: unknown user name or bad
password" and it seems to me that I have no way neither to change the password nor to distinguish a wrong
credential error from a an error due to a disabled account, a password expired.
Do you have any suggestion to solve this problem.
Thanks
Fabrizio
Oops sorry.., posted to wrong question.
"Henry" <ig******@hotmail.com> wrote in message
news:uw**************@TK2MSFTNGP10.phx.gbl... Forgot to mention, I'm using ADAM here. Anyone?
"Fabrizio" <xx*********************@xxxhotmail.com> wrote in message news:eL*************@TK2MSFTNGP11.phx.gbl... (Sorry for the crosspost, but I really don't know which is the right newsgroup!) Hi all,
I try to change the password to a user that as to change the password at first logon: try
{
DirectoryEntry de = new DirectoryEntry();
de.AuthenticationType = AuthenticationTypes.ServerBind | AuthenticationTypes.Secure;
de.Path = "LDAP://10.0.50.20/cn=users,dc=newtesthp,dc=com";
de.Username = "cn=fv,cn=users,dc=newtesthp,dc=com";
de.Password = "fv";
DirectorySearcher ds = new DirectorySearcher(de, "cn=fv");
SearchResult sr = ds.FindOne();
DirectoryEntry usr = sr.GetDirectoryEntry();
usr.Invoke("ChangePassword",new object[]{"fv","12345qwert"});
usr.CommitChanges();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
I an exception that says "Logon failure: unknown user name or bad password" and it seems to me that I have no way neither to change the password nor to distinguish a wrong credential error from a an error due to a disabled account, a password expired.
Do you have any suggestion to solve this problem.
Thanks
Fabrizio
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ashish Shridharan |
last post by:
Hi All
How does one add users to Windows 2000 using the
System.DirectoryServices class ??
Ashish
|
by: hykim |
last post by:
Hello, everyone.
according to MSDN, there is any constructor of
System.DirectoryServices.SearchResultCollection Class.
if I implement DirectorySearcher.FindAll() method by myself, then how can I...
|
by: Stephanie Stowe |
last post by:
Hi. I am trying to read information out of the IIS metabase (v5.1). Observe
the following code:
using System;
using System.DirectoryServices;
using System.Reflection;
namespace ADSI1
{...
|
by: Xnet |
last post by:
I need to change password of a local user of a W2003, without Active
Directory.
I need to do it from an application created with VB2005.
Thanks!
|
by: RSH |
last post by:
I am using System.DirectoryServices to query our AD in order to get
information about users.
I am having problems understanding how to get at the Username and the Email
address (to begin with)
...
|
by: fredfrog22 |
last post by:
The following is an extract from a C# console application that creates
a Virtual Directory on IIS 5 or 6.
This code works on XP, Windows 2003 Server, Windows 2000.
It does not work on Windows...
|
by: Marc the Demi-Programmer |
last post by:
I am overriding WncProc to make sure my form's location stays within
specified parameters. Basically, it has to stay at the top of the
screen and not be off to either of the sides. All that works...
|
by: richardaz |
last post by:
I have been working on a project to search for 250,000 different
records in ActiveDirectory. The process takes a long time and I have
tried everything to make it faster. Currently using...
|
by: =?Utf-8?B?TmFt?= |
last post by:
On my ASP.NET 2.0 website project on VS 2005, I am getting the following
error when building the solution:
“The type or namespace name 'ADSI' does not exist in the namespace
'myNameSpace' (are...
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |