Error:
Password couldn't be changed due to restrictions
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80070775): The referenced account is currently locked out and may not be logged on to. (Exception from HRESULT: 0x80070775) --- End of inner exception stack trace --- at System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args)
This is the codes for the password reset. Could anyone kindly help me to check if there is anything wrong in these codes??? Thanks!!!
///
/// Sets a new password for user in Active Directory.
///
/// Staff's Login ID
/// Staff's New Login Password
public void SetPassword(String username, String password)
{
DirectoryEntry entry = createDomainDirectoryEntry();
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter =
"(SAMAccountName=" + username + ")";
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)
{
PasswordStatus = error.Message.ToString();
}
}
try
{
entry.Invoke(
"SetPassword", new object[] { password });
entry.CommitChanges();
PasswordStatus =
"Password has been changed";
Unlock(entry);
}
catch (Exception)
{
PasswordStatus =
"Password couldn't be changed due to restrictions";
}
}
else
{
PasswordStatus =
"User not found or bad password";
}
}
// END OF PasswordStatus METHOD
Replies
Know the answer? Post it — somebody with the same question will find it here.