0

當AD中的用戶密碼設置爲「下次登錄時更改」時,用戶無法登錄,因爲他們的密碼顯示爲不正確。我希望能夠在認證時確定這一點,並提示用戶更改密碼。確定用戶密碼何時過期Active Directory,拋出異常錯誤

我明白要做到這一點,我需要趕上DirectoryServicesCOMException如本question描述然而該異常沒有被拋出而不是拋出的異常是一個Interop.COMException是越往上繼承hierarchy

這不包含所需的信息來確定密碼是否需要更改或只是不正確。

private bool IsAuthenticated(string Path, string UserName, string Password) 
{ 
    try 
    { 
     DirectoryEntry userEntry = new DirectoryEntry(Path, UserName, Password); //, AuthenticationTypes.Signing) 

     var obj = userEntry.NativeObject; 
     return true; 
    } 
    catch (DirectoryServicesCOMException ex) 
    { 
     if (ex.ExtendedErrorMessage.Contains(" 773,") || ex.ExtendedErrorMessage.Contains("532")) 
     { 
      EventLogController.Instance.AddLog("Password expired", ex.ExtendedErrorMessage, Globals.GetPortalSettings(), -1, DotNetNuke.Services.Log.EventLog.EventLogController.EventLogType.ADMIN_ALERT); 
      System.Web.HttpContext.Current.Response.Cookies["sync_expiryToken"].Value = "1"; 
      return true; 
     } 
     return false; 
    } 
    catch (COMException ex) 
    { 
     EventLogController.Instance.AddLog("Password wrong", ex.ToString(), Globals.GetPortalSettings(), -1, DotNetNuke.Services.Log.EventLog.EventLogController.EventLogType.ADMIN_ALERT); 
     return false; 
    } 
    catch (Exception ex) 
    { 
     Exceptions.LogException(ex); 
     return false; 
    } 
} 

回答

0

我找到了答案,最終,

某些身份驗證類型只拋出一個COMException而非DirectoryServicesCOMException

設置身份驗證類型AuthenticationTypes.None在LDAP解決的問題。

相關問題