Please Read: Significant Update Planned, Migrating Forum Software This Month

See more
See less

change password AD using

  • Filter
  • Time
  • Show
Clear All
new posts

  • change password AD using

    I would want to ask you to help me correct a problem like this:

    This is a code i use to change password on AD

     public bool ChangePasswordAD(string strLogin, string strOldPasswd, string strNewPasswd)
             {   string domainAndUsername = "" + @"\" + strLogin;
                 DirectoryEntry entry = new DirectoryEntry(ConfigurationManager.AppSettings["LDAPpath"].ToString(), domainAndUsername, strOldPasswd, AuthenticationTypes.Secure);
                 DirectorySearcher searcher = new DirectorySearcher(entry);
                searcher.Filter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=strLogin))";
                 SearchResult objResult = searcher.FindOne();
                DirectoryEntry objLoginEntry = (objResult != null) ? objResult.GetDirectoryEntry() : null;
                 if (objLoginEntry != null)
                     object obj = objLoginEntry.Invoke("ChangePassword", new object[] { strOldPasswd, strNewPasswd });
                    obj = null;
                entry = null;
                 searcher = null;
                objResult = null;
                 objLoginEntry = null;
             catch (Exception ex)
                 return false;
             return true;
    The problem here is :

    - If the Admin creates a user and don't check " User must change password the next logon " then the user from client can change password successfully , and without error
    - But if the Admin creates a user and check " User must change password the next logon " then the user can't change password .
    I know the error caused by : When "User must change password the next logon" is checked, user have to change it immediately in a sign in window, and use new password to login instead of the old password .
    How can I deal with this problem ?
    Could you all take a little of your time to help me ? Thanks you.
    Last edited by biggles77; 17th December 2009, 20:21. Reason: Wrap script in CODE tag