locked
Changing User Password in ADAM RRS feed

  • Question

  • I am authenticating my users from ADAM .

    I write some code to change the user password .

    when the user enters the correct old password and the new password matching the policy ,every thing goes good.

    but when the user enters wrong old password or the new password is not matching the password policy the following error appear:

    Message = "Exception has been thrown by the target of an invocation."

    InnerException = {"A constraint violation occurred. (Exception from HRESULT: 0x8007202F)"}

    I want to show customized message to user telling him what is the problem in his password or what the policy that his password doesn`t meet

     

    int portNumber = 7000;
    string serverName = "192.168.66.2";
    string usersPartitionDir="cn=" + HttpContext.Current.User.Identity.Name + ",cn=Users,cn=partition1,dc=TestADAM,dc=com";
    string adminUserName = "test";
    string adminPassword = "test";
    
    string directoryPath = "LDAP://" + serverName + ":" + portNumber + "/" + usersPartitionDir;
    
    DirectoryEntry ent = new DirectoryEntry(directoryPath, adminUserName, adminPassword);
    
    ent.AuthenticationType = AuthenticationTypes.Signing | AuthenticationTypes.Sealing | AuthenticationTypes.Secure;
    
     ent.RefreshCache();
    
    
    const long ADS_OPTION_PASSWORD_PORTNUMBER = 6;
    const long ADS_OPTION_PASSWORD_METHOD = 7;
    const int ADS_PASSWORD_ENCODE_CLEAR = 1;
    
    ent.Invoke("SetOption", new object[] { ADS_OPTION_PASSWORD_PORTNUMBER, portNumber });
    ent.Invoke("SetOption", new object[] { ADS_OPTION_PASSWORD_METHOD, ADS_PASSWORD_ENCODE_CLEAR });
    
    try
    {
       ent.Invoke("ChangePassword", new object[] { wtxtCurrentPassword.Text, wtxtNewPassword.Text });
       return true;
    }
    catch (Exception ex)
    {
        ShowError("The current password is not correct or The new Password doesn`t meet the minimum policy requirements "+",<br />message:" + ex.Message + "<br />" + ex.InnerException);
    }
            
    
    
    

     

    • Moved by Rudedog2 Thursday, August 26, 2010 1:05 PM (From:Visual C# General)
    Thursday, August 26, 2010 6:50 AM

All replies