locked
BadPassword Exception - Active Directory. RRS feed

  • Question

  • User-1180915401 posted

    Hi, 

    I am using advapi32.dll and kernal32.dll in my web application and I am getting “BadPassword” exception while changing the default/temporary password. This exception is not consistent.

    The scenario is the application hosted in Server1 and the Active Directory in Server2.

    Can anyone please help me?

    --

    Selva

    Monday, December 24, 2012 10:50 AM

Answers

  • User-166373564 posted

    Hi selvakumarbalan

    selvakumarbalan

    I am getting “BadPassword” exception while changing the default/temporary password.

    You can try change Passwords With Active Directory using LDAP path,

    if (newpassword.Text.ToString() == checknewpassword.Text.ToString())

                {

                  // Just fetch the user's XXXX\xxx login name

                    SPWeb webContext = SPControl.GetContextWeb(Context);

                    string strLoginName = webContext.CurrentUser.LoginName;

                    int iPosition = strLoginName.IndexOf("\\") + 1;

                    strLoginName = strLoginName.Substring(iPosition);

                    DirectoryEntry entry = new DirectoryEntry("LDAP://blfoley.local", strLoginName, oldpassword.Text.ToString(),AuthenticationTypes.Secure);

                    DirectorySearcher search = new DirectorySearcher(entry);

                    search.Filter = "(SAMAccountName=" + strLoginName + ")";

                    search.SearchScope = SearchScope.Subtree;

                    search.CacheResults = false;

                    SearchResultCollection results = search.FindAll();

                    if (results.Count > 0)

                    {

                        foreach (SearchResult result in results)

                        {

                            try

                            {

                                entry = result.GetDirectoryEntry();

                            }

                            catch (Exception error)

                            {

                                output.Text += "" + error.Message.ToString();

                            }

                        }

                        try

                        {

                            entry.Invoke("ChangePassword", new object[] { oldpassword.Text.ToString(), newpassword.Text.ToString() });

                            entry.CommitChanges();

                            output.Text += "Password is changed";

                        }

                        catch (Exception)

                        {

                            output.Text += " Password couldn't be changed due to restrictions<b>";

                        }

                    }

                    else

                    {

                        output.Text += "&lt;BR> User not found or bad password";

                    }

                }

                else

                {

                    output.Text += "&lt;BR>Passwords don't match";

                }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 30, 2012 8:51 PM