Team LiB
Previous Section Next Section

Changing Passwords

Using the ChangePassword property, you can easily give a user a different password. The following example shows how to change a user's password.

Note 

You do not need to call CommitChanges on ChangePassword calls, because this information is not stored in the cache.

Code Example: Changing Passwords
Start example
using System;
using System.DirectoryServices;
using ActiveDs;

namespace ChangePassword
{

        class Class1
        {

               [STAThread]
               static void Main(string[] args)
               {
                     string Path =
                        "LDAP://XYZ.com/CN=Welby,OU=gregmcb,DC=XYZ, DC=com";
                     string User = "XYZ\\gregmcb";
                     string Password = "gregmcb";
                     DirectoryEntry Entry =
                        new DirectoryEntry(Path, User, Password);

                     //This code allows you to retrieve native COM pointers
                     //for interfaces such as IADSUser, IADS, and more.
                     IADsUser IUsr = (IADsUser) Entry.NativeObject;
                     IUsr.ChangePassword("Yes", "welby");

                     Entry.Close();
               }
        }
}
End example

Team LiB
Previous Section Next Section