2017-09-21 104 views
2

我的身份驗證嘗試時,用戶登錄不工作作爲expected.It總是會返回其他部分想嘗試AUTH驗證::嘗試不工作的登錄

public function tunneluserAuth(Request $request) 
{ 



    $this->validate($request, [ 
     'email' => 'required|email', 
     'password' => 'required', 
    ]); 

$password=Hash::make($request->input('password')); 

if (Auth::attempt(array('userLogin' => $request->input('email'), 
    'userPassword' => $password))) { 

    echo "hi";exit; 

} 
else { 

echo "here";exit; 

} 

} 

時,我的auth.php頁面就像是,

'providers' => [ 
    'users' => [ 
     'driver' => 'eloquent', 
     'model' => App\Entity\User::class, 
    ], 

    'companyUsers' => [ 
     'driver' => 'database', 
     'table' => 'companyUsers', 
    ], 
], 

但它總是返回else condition.why?

回答

0

試試這個片斷:

<?php 

namespace App\Http\Controllers; 

use Illuminate\Support\Facades\Auth; 

class LoginController extends Controller 
{ 
    /** 
    * Handle an authentication attempt. 
    * 
    * @return Response 
    */ 
    public function authenticate() 
    { 
     if (Auth::attempt(['email' => $email, 'password' => $password])) { 
      // Authentication passed... 
      return redirect()->intended('dashboard'); 
     } 
    } 
}` 

來源:Laravel Documentation

1

嘗試使用身份驗證憑據鍵作爲代替USERLOGIN和userPassword的電子郵件和密碼。

public function tunneluserAuth(Request $request) 
{ 

    $this->validate($request, [ 
     'email' => 'required|email', 
     'password' => 'required', 
    ]); 

    if (Auth::attempt(['email' => $request->input('email'), 
    'password' => $request->input('password')])) { 

    echo "hi";exit; 

} 
else { 

echo "here";exit; 

} 

} 

如果你仍然想使用自己的證書密鑰使用本 -

$userData = User::where('userLogin',$request->input('email'))->first(); 
Auth::loginUsingId($userData->id); 

希望這會爲你工作。