none
Is a Change password process on OWA the same as ChangePassword method of System.DirectoryServices ????? RRS feed

  • Question

  • Hi all,

    I am wondering whether Change password method as figure shown in below  is the same as  ChangePassword method of System.DirectoryServices  or not.

    I post sample code as well. below code is pretty straightforward to change password.

    It is able to do both active user and expired password user.

        static void Main(string[] args)
            {
    
                string ldap = "LDAP://spxdev.local";
                string strUserName = "william";
                string strOldPassword = "P@ssw0rd";
                string strNewPassword = "W!11Li@m#123";
                string domain = "spxdev.local";
    
                XChangeMyPassword(ldap, domain, strUserName, strOldPassword, strNewPassword);
    
    
            }
    
    
     public static void XChangeMyPassword(string ldap, string domainName, string userName, string currentPassword, string newPassword)
            {
                try
                {
                    string ldapPath = ldap;
                //   DirectoryEntry directionEntry = new DirectoryEntry(ldapPath, domainName + "\\" + userName, currentPassword);
                   DirectoryEntry directionEntry = new DirectoryEntry(ldapPath, domainName + "\\" + "administrator", "P@ssw0rd");
                    if (directionEntry != null)
                    {
                        DirectorySearcher search = new DirectorySearcher(directionEntry);
                        search.Filter = "(SAMAccountName=" + userName + ")";
                        SearchResult result = search.FindOne();
                        if (result != null)
                        {
                            DirectoryEntry userEntry = result.GetDirectoryEntry();
                            if (userEntry != null)
                            {
                               userEntry.Invoke("ChangePassword", new object[] { currentPassword, newPassword });
                                userEntry.CommitChanges();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

    The main problem is that I cannot change password of expired user through   OWA , instead  Above code is successful.

     Thank a lot

    John



    Tuesday, November 22, 2016 10:32 AM

All replies

  • Hi DotNet Gangester,

    Did you try using the Domain\Username format when changing the password in OWA?

    Good luck!

    Shane

    Thursday, November 24, 2016 3:19 PM