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.
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 += "<BR> User not found or bad password";
}
}
else
{
output.Text += "<BR>Passwords don't match";
}
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
None
0 Points
2 Posts
BadPassword Exception - Active Directory.
Dec 24, 2012 10:50 AM|selvakumarbalan|LINK
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
All-Star
32817 Points
3815 Posts
Re: BadPassword Exception - Active Directory.
Dec 30, 2012 08:51 PM|Angie xu - MSFT|LINK
Hi selvakumarbalan
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 += "<BR> User not found or bad password";
}
}
else
{
output.Text += "<BR>Passwords don't match";
}
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.