2017-05-08 3 views
0

버튼이 있으며 클릭 이벤트가 다양한 유효성 검사 코드를 통해 실행 된 다음 유효성 검사를 통과하면 'ChangePassword'메소드가 호출됩니다.Active Directory 비밀번호 변경 관련 문제 처리 관련 문제

public void ChangePassword(string userName, string oldPassword, string newPassword) 
    { 
     try 
     { 
      new ApplusActiveDirectoryUtil().CheckParameter(ref userName, true, true, false, 21, "User Name"); 

      DirectoryEntry userEntry = _directoryInfo.GetUserEntry(userName); 
      userEntry.Invoke("ChangePassword", new Object[] { oldPassword, newPassword }); 
      //unlock account 
      userEntry.Properties["LockOutTime"].Value = 0x0000; 
      userEntry.CommitChanges(); 
      userEntry.Dispose(); 
      userEntry.Close(); 
     } 
     catch (Exception ex) 
     { 
      _directoryInfo.Initialize(); 
      DirectoryEntry domainEntry = _directoryInfo.DomainDirectoryEntry; 
      ApplusActiveDirectoryDomainPolicy domainPolicy = new ApplusActiveDirectoryDomainPolicy(_directoryInfo.DomainDirectoryEntry); 
      string message = "Password entered was wrong or password entered was the same as the previous " + domainPolicy.PasswordHistoryLength + " passwords set."; 
      throw new Exception(message, ex); 
     } 
    } 

난 데 문제는이 라인 ...

userEntry.Invoke("ChangePassword", new Object[] { oldPassword, newPassword }); 

오류를 줄 것입니다 ...

함께 System.Runtime.InteropServices.COMException (0x80070056) : 지정한 네트워크 암호가 올바르지 않습니다.

사용자가 '현재 암호'텍스트 상자에 암호를 입력했지만 현재 암호와 일치하지 않을 때 오류가 발생합니다.

내가 수행하여이 문제를 처리하기 위해 노력했다

..

if (txtConfirmNewPassword.Text != user.Password) 
    { 
     SetChangePasswordMessage("Password entered was wrong"); 
    } 

하지만 내가 읽은 바로는, 사용자 AD 암호를 검색 할 수 없습니다

.

잡을 필요없이이 오류를 정상적으로 처리 할 수 ​​있습니까?

+1

먼저 자격 증명이 유효한지 확인한 다음 통과하면 암호 변경을 호출합니다. – Equalsk

+0

그게 다야! 나는 당신의 충고와 함께 일하고있다. 고맙습니다 – MadDev

답변

0

감사의 말에 감사드립니다. 해결책을 찾았습니다.

먼저 자격 증명의 유효성을 검사해야했습니다. 자격 증명이 유효하면 ChangePassword 메서드를 호출하십시오.

  bool IsValidate = Membership.ValidateUser(user.UserName, txtOldPassword.Text); 
      if (!IsValidate) 
      { 
       SetChangePasswordMessage("Password entered was wrong or password entered was the same as the previous " + domain.PasswordHistoryLength + " passwords set."); 
      } 
      else 
      { 
       new ApplusActiveDirectoryMembership(admin.AdminADUserName, admin.AdminADPassword).ChangePassword(user.UserName, txtOldPassword.Text, txtConfirmNewPassword.Text); 
       SetChangePasswordMessage("The password has been successfully changed."); 
      }