3

Active Directory 사용자가 암호를 업데이트 할 수있는 웹 응용 프로그램의 일부로 다음 코드를 사용합니다 (Active Directory와 Gmail의 경우). System.DirectoryServices.AccountManagement에서 C#을 사용하고 있습니다.C# Active Directory 호출 "ChangePassword"가 도메인에 연결할 수 없습니다.

이 코드는 어제부터 어제

try 
{ 
    State.log.WriteLine("Connecting LDAP."); 
    string ldapPath = "LDAP://192.168.76.3"; 
    DirectoryEntry directionEntry = new DirectoryEntry(ldapPath, domainName + "\\" + userName, currentPassword); 
    if (directionEntry != null) 
    { 
     DirectorySearcher search = new DirectorySearcher(directionEntry); 
     State.log.WriteLine("LDAP Connected, searching directory for SAMAccountName"); 
     search.Filter = "(SAMAccountName=" + userName + ")"; 
     SearchResult result = search.FindOne(); 
     if (result != null) 
     { 
      State.log.WriteLine("Getting User Entry."); 
      DirectoryEntry userEntry = result.GetDirectoryEntry(); 
      if (userEntry != null) 
      { 
       State.log.WriteLine("Setting Password"); 
       if (force) 
       { 
        userEntry.Invoke("SetPassword", new[] { newPassword }); 
       } 
       else 
       { 
        userEntry.Invoke("ChangePassword", new object[] { currentPassword, newPassword }); 
       } 
       userEntry.CommitChanges(); 
       State.log.WriteLine("Changes Committed to ActiveDirectory."); 
      } 
      else 
      { 
       State.log.WriteLine("Could not get user Entry..."); 
      } 
     } 
     else 
     { 
      State.log.WriteLine("Search returned no results."); 
     } 
    } 
    else 
    { 
     State.log.WriteLine("Could not connect to LDAP with given username and passwd"); 
    } 
} 

때까지 일했다,이 코드 라인에 있습니다 :

userEntry.Invoke("ChangePassword", new object[] { currentPassword, newPassword }); 

을 한 후 다음과 같은 예외가 발생합니다 :

을 [ 8:37:00 AM] : 암호 요구 사항 충족.

[8:37:00 AM] : LDAP 연결 중입니다.

[오전 8시 37분 0초] :

SAMAccountName을

에 대한 LDAP 연결, 검색 디렉토리 [오전 8시 37분 1초] : 사용자 입력 받기.

[오전 8시 37분 1초] : 비밀번호를 설정

[오전 8시 37분 1초] : 제이슨에 대한 Windows 암호를 재설정 할 수 없습니다.


호출 대상에 의해 예외가 발생했습니다.


시스템에서 도메인 컨트롤러에 연결하여 인증 요청을 처리 할 수 ​​없습니다. 나중에 다시 시도 해주십시오. (HRESULT에서 예외 : 0x800704F1)

여전히 잘 작동 "SETPASSWORD"를 사용하여 "강제"옵션이 있지만, 관리자가 아닌 사용자에 의해 호출 할 수있는 "과 changepassword"방법은하지 않습니다.

답변

0

이달 초 Microsoft released a security patch, 암호 변경 영역의 일부 취약점을 해결했습니다. 특히 암호를 변경할 때 실패한 Kerberos 인증 후에 NTLM 인증에 대한 대체 업데이트가 차단되었습니다.

업데이트에 대한 자세한 내용은 here을 참조하십시오.

+0

이것은 매우 도움이됩니다. 감사합니다. –

1

변경 userPrincipal.ChangePassword ("Old pass", "New Pass"); 에 userPrincipal.SetPassword(model.NewPassword);

+0

관리 권한이없는 사용자 conetext는 SetPassword를 호출 할 수 없습니다. –

0

Microsoft는이 문서를 업데이트했습니다 : https://support.microsoft.com/en-us/kb/3177108. 여기서 그들은 원래의 "수정 사항"에 의해 생성 된 문제와 Kerberos 및 셀프 서비스 암호 재설정 작업에 대한 몇 가지 팁을 제공했습니다.

2016 년 10 월 11 일 Microsoft는 https://technet.microsoft.com/en-us/library/security/ms16-101.aspx과 관련된 패치를 다시 릴리스하여 원래 업데이트 (로컬 계정의 암호를 더 이상 변경할 수 없다는 사실을 포함하여 https://support.microsoft.com/en-us/kb/3177108에서 읽을 수 있음)로 인한 문제를 해결했습니다.

1

해결 방법을 찾았으며 게시하는 것을 잊어 버렸습니다.내가 한 것은 위의 코드를 사용하여 사용자를 인증 한 다음 "ForceChangePassword"메서드를 호출하는 것입니다.

public static void ForceChangeADPassword(String username, String newPassword) 
{ 
    String DN = ""; 
    try 
    { 
     DN = GetObjectDistinguishedName(objectClass.user, returnType.distinguishedName, username, DOMAIN_CONTROLLER_IP); 
    } 
    catch(Exception e) 
    { 
     throw new PasswordException(String.Format("Could not find AD User {0}", username), e); 
    } 

    if(DN.Equals("")) 
     throw new PasswordException(String.Format("Could not find AD User {0}", username)); 

    DirectoryEntry userEntry = new DirectoryEntry(DN.Replace("LDAP://", LdapRootPath), "accounts", AcctPwd); 
    userEntry.Invoke("SetPassword", new object[] { newPassword }); 
    userEntry.Properties["LockOutTime"].Value = 0; 

    userEntry.CommitChanges(); 
    userEntry.Close(); 
}