PC Review


Reply
Thread Tools Rate Thread

Changing Password to an account that has to change password at first logon using System.DirectoryServices

 
 
Fabrizio
Guest
Posts: n/a
 
      11th May 2004
(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


 
Reply With Quote
 
 
 
 
Ben Dewey
Guest
Posts: n/a
 
      11th May 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> (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
>
>



 
Reply With Quote
 
Joe Kaplan \(MVP - ADSI\)
Guest
Posts: n/a
 
      11th May 2004
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > (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
> >
> >

>
>



 
Reply With Quote
 
Fabrizio
Guest
Posts: n/a
 
      12th May 2004
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" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > (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
> >
> >

>
>



 
Reply With Quote
 
Ben Dewey
Guest
Posts: n/a
 
      12th May 2004
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)" <(E-Mail Removed)> wrote
in message news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > (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
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Joe Kaplan \(MVP - ADSI\)
Guest
Posts: n/a
 
      12th May 2004
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" <(E-Mail Removed)> wrote in message
news:e%(E-Mail Removed)...
> 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)" <(E-Mail Removed)> wrote
> in message news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> > > 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" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > (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
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Joe Kaplan \(MVP - ADSI\)
Guest
Posts: n/a
 
      12th May 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:#(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > (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
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Fabrizio Viggiani
Guest
Posts: n/a
 
      13th May 2004
Ciao Joe,

What can I use beside NetUserChangePassword?

Fabrizio


"Joe Kaplan (MVP - ADSI)" <(E-Mail Removed)> wrote
in message news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:#(E-Mail Removed)...
> > > 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" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > (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
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Joe Kaplan \(MVP - ADSI\)
Guest
Posts: n/a
 
      13th May 2004
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" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> Ciao Joe,
>
> What can I use beside NetUserChangePassword?
>
> Fabrizio
>
>
> "Joe Kaplan (MVP - ADSI)" <(E-Mail Removed)> wrote
> in message news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > 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" <(E-Mail Removed)> wrote in message
> > > news:#(E-Mail Removed)...
> > > > 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" <(E-Mail Removed)> wrote in message
> > > > news:(E-Mail Removed)...
> > > > > (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
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Henry
Guest
Posts: n/a
 
      1st Jul 2004
Forgot to mention, I'm using ADAM here. Anyone?

"Fabrizio" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> (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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
System.DirectoryServices.AccountManagement: Change existing password MarkusJ_NZ Microsoft Dot NET Framework 0 18th Jun 2009 04:37 AM
Changing a users password without knowing the old password nor the answer to the password question AAaron123 Microsoft ASP .NET 2 16th Jan 2009 02:08 PM
XP randomly asks for password or password doesn't work problem. GET ACCESS TO USER ACCOUNT WITH PASSWORD Dooger@the.dog.house Windows XP General 0 24th Apr 2007 03:53 AM
Password expires and account state changes to "user must change password on next logon" dmohanty@gmail.com Microsoft Windows 2000 Active Directory 0 13th Sep 2005 10:51 AM
Other user account able to change my password without old password prompt noddyt Windows XP Security 1 12th Aug 2005 11:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:06 AM.