1
  • Laravel 版本:5.4
  • Adldap2-Laravel 版本:“^3.0”,
  • PHP版本:5.6.30

我设法使与 AD 的连接工作,但我似乎无法使 Auth::attempt 工作。它总是返回 false。有人有想法或提示吗?

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()->attempt(request()->only('username', 'password'))

正在给我一个 ErrorException: Missing argument 2 for Adldap\Auth\Guard::attempt(),在第 63 行的 /media/sf_www/prm/app/Http/Controllers/Auth/LoginController.php 中调用并定义<

更新:

我设法取得了成功:

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

我可以成功,奇怪的是我必须使用CN名称作为用户名。如果我使用“tba”的 samaccountname,它就不起作用。

更有趣的是,Auth 根本不起作用。返回假

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

我可能需要一些帮助/介绍。

4

1 回答 1

1

我认为这很简单。该函数需要 2 个参数,您传递给它一个参数。快速查看文档显示第一个参数是用户名,第二个参数是密码。这样做时,request()->only('args')您会返回一个array.

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

于 2017-06-09T08:36:15.770 回答