2017-06-09 28 views
0
  • Laravel版本:5.4
  • Adldap2-Laravel版本: 「^ 3.0」,
  • PHP版本:30年6月5日

我設法讓連接工作的AD,但我不能似乎使Auth :: attemptnt工作。 它總是會返回false。任何人有想法或暗示?Adldap :: search() - > users() - > get();

public function login(Request $request) { 

    $search = Adldap::search()->where('samaccountname', '=', 'tba')->get(); 
    // this is returning the correct user 
    dd($search); 

    //'username' => 'tba' 
    // 'passwrod' => 'is the entered password' 
    //this goes into error part 
    if (Auth::attempt(request()->only('username', 'password'))) { 
     dd('success'); 
    } else { 
     dd('error'); 
    } 

} 

'用戶名'=> [

/* 
|-------------------------------------------------------------------------- 
| LDAP 
|-------------------------------------------------------------------------- 
| 
| This is the LDAP users attribute that you use to authenticate 
| against your LDAP server. This is usually the users 
|'sAMAccountName'/'userprincipalname' attribute. 
| 
| If you'd like to use their username to login instead, insert `samaccountname`. 
| 
*/ 

'ldap' => 'samaccountname', 

/* 
|-------------------------------------------------------------------------- 
| Eloquent 
|-------------------------------------------------------------------------- 
| 
| This is the attribute that is used for locating 
| and storing the LDAP username above. 
| 
| If you're using a `username` field instead, change this to `username`. 
| 
| This option is only applicable to the DatabaseUserProvider. 
| 
*/ 

'eloquent' => 'username', 

啊右和

Adldap :: AUTH() - >嘗試(請求() - >僅( '用戶名',「口令'))

給我一個ErrorException: 缺少Adldap \ Auth \ Guard :: attempt()的參數2,在/media/sf_www/prm/app/Http/Controllers/Auth/LoginController.php中調用第63行並定義爲<

UPDATE:

我設法去獲得成功:

if (Adldap::auth()->attempt(request()->get('username'), request()->get('password'))) { 
    dd('success'); 
} else { 
    dd('error'); 
} 

我能到成功的,奇怪的是我必須使用CN名稱作爲用戶名。 如果我使用samaccountname這是「tba」它不起作用。

更有趣的是,Auth根本不工作。返回FALSE

Auth::attempt(request()->only('username', 'password')) 

我可以在這裏需要一些幫助/介紹。

回答

1

我覺得這很簡單。該函數需要2個參數,你傳遞了一個參數。快速查看文檔顯示第一個參數是用戶名,第二個參數是密碼。在做request()->only('args')時,你會得到一個array

取而代之的是做Auth::attempt(request()-get('username'), request()->get('password'))

+0

是的,那是我的錯誤。代碼現在正在運行,但我仍然被返回false。 – therabbityouknow

相關問題