0
Answer

HELP!!! : Problem Dealing With The Reset Password

Mr lan

Mr lan

14y
4.2k
1

I have some problems while dealing with the reset password of my program. Here are the following errors, will be grately if anyone can help . Thanks ^^
 
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!!!
 
/// <summary>
 

/// Sets a new password for user in Active Directory.
 

/// </summary>
 

/// <param name="username">Staff's Login ID</param>
 

/// <param name="password">Staff's New Login Password</param>
 

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 =


"<B>Password couldn't be changed due to restrictions<B/>";
}
}
 


else
{
PasswordStatus =

"</BR>User not found or bad password";
}
}


// END OF PasswordStatus METHOD