change password AD using asp.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bemytthm
    New Member
    • Dec 2009
    • 2

    change password AD using asp.net

    I just want to ask abt communicate with AD using ASP.net. I would want to ask you all to help me correct a problem like this:

    This is a code i use to change password on AD

    Code:
    public bool ChangePasswordAD(string strLogin, string strOldPasswd, string strNewPasswd)
        {
            try
            {   string domainAndUsername = "aloha.com" + @"\" + 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 });
                    objLoginEntry.CommitChanges();
                    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 ?
    Thanks you.
    Last edited by Frinavale; Dec 17 '09, 06:37 PM. Reason: Please post code in [code] ... [/code] tags. Changed bold tags into code tags.
  • semomaniz
    Recognized Expert New Member
    • Oct 2007
    • 210

    #2
    Please read

    Comment

    • bemytthm
      New Member
      • Dec 2009
      • 2

      #3
      i already read it. But it didn't help.
      The problem here is
      if i had an DirectoryEntry object , i could easily do eveything such as finding, setting properties, getting properties, and so on..
      But when the admin checked that property like that, i cann't login successfully to use DirectoryEntry object.

      Comment

      Working...