簡體   English   中英

Laravel 中的 LDAP 綁定消息

[英]Ldap bind message in Laravel

我有個問題。 目前我正在使用 ldap 連接。

我對 ldap 連接沒有任何問題,因為我使用的是手動 ldap 代碼。 我與 ldap 的連接是成功的。

當我輸入正確的用戶名和密碼時,一切似乎都很好。 輸入錯誤密碼時出現問題,頁面將顯示“ErrorException ldap_bind(): Unable to bind to server: Invalid credentials”,頁面還顯示所有登錄功能代碼。

如何在頁面不顯示 ErrorException 的情況下顯示正確的錯誤消息? 有關信息,我沒有使用任何 ldap 安裝框架。

例如我的代碼:

public function process_login(Request $request)
{
  $username = $request->username;
  $password = $request->password;

  $ldaphost= "xxxx";
  $ldapconn = ldap_connect($ldaphost) or die("That LDAP-URI was not parseable");
  $ldap_credential= 'uid='.$username.',cn=xxx';
  $ldappass = $password;

if ($ldapconn) 
{  
  $ldapbind = ldap_bind($ldapconn, $ldap_credential, $ldappass);

  if ($ldapbind) {
     return redirect()->route('dashboard');
  }
  else
      {
        return Redirect::back()->withErrors(['msg', 'Wrong Password/Username']);
      }
}
}

登錄.blade:

@if($errors->any())
        <h4>{{$errors->first()}}</h4>
@endif

任何人都可以幫助我嗎?

我和其他許多人一樣,在使用 PHP 的 LDAP 身份驗證時遇到了同樣的問題。 完全同意,顯示這些錯誤非常草率。 信不信由你,最常見的解決方案之一是使用標准 PHP @使綁定過程靜音,以避免顯示不需要的錯誤消息。

在您的情況下,類似於:

if (@ldap_bind($ldapconn, $ldap_credential, $ldappass)) {
   return redirect()->route('dashboard');
}
else
{
    return Redirect::back()->withErrors(['msg', 'Wrong Password/Username']);
}

當您在網站上看到來自 PHP 的消息時,通常意味着您的 PHP 安裝配置錯誤。

在生產網站上,PHP.ini 文件(使用 phpinfo 頁面查找 PHP.ini 文件的位置)應該將display_errorsdisplay_startup_errors設置為false但將error_log設置為 euther syslog或錯誤日志文件的路徑。

此外,您不應將error_reporting設置為 0,因為您將很難調試生產站點。

如果您不希望來自ldap_bind的消息顯示在您的錯誤日志中,您應該使用set_error_handler設置一個錯誤處理程序,該處理程序專門刪除這條消息,可能僅針對此函數調用,並重置原始錯誤處理程序。

特別是在ldap_bind情況下, ldap_bind您可能會在調試發生的事情時遇到問題,因為這通常是實際打開與服務器的連接的第一個命令,因此該函數的消息中會出現很多連接問題。 當您使用@使函數中的每條消息靜音時,您將永遠不會看到

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM