2017-04-02 42 views
1

如果用戶嘗試登錄到我的Laravel應用程序,並且密碼與數據庫中的「密碼」列不匹配,我想檢查它是否與另一個密碼列(「old_system_password」 )。使用Laravel 5.4自定義登錄密碼檢查

我使用默認的Laravel身份驗證系統,據我所知我應該能夠創建一個新的「AuthController」並覆蓋內置的身份驗證方法。但是我沒有在供應商文件夾中找到任何處理密碼匹配的方法,也不知道如何告訴Laravel使用我的方法而不是默認方法。

我已經在網上搜索了這個,但是我發現的任何解決方案似乎都只適用於舊版本的Laravel。

任何想法?

回答

-1

首個解決方案:https://laravel.com/docs/5.4/authentication#authenticating-users

二解決方案:

1:就在LoginController.php

public function authenticate() 
{ 
    if (Auth::attempt(['email' => $email, 'password' => $password])) { 
     // Authentication passed... 
     return redirect()->intended('dashboard'); 
    } else if(Auth::attempt(['email' => $email, 'password' => $old_password]) { 
     return redirect()->intended('dashboard'); 
    } 
} 

檢查覆蓋public function authenticate()運行php artisan event:generate產生laravel事件。

2:運行php artisan make:event CheckOldPassword

3:添加事件在EventServiceProvider.php 'Illuminate\Auth\Events\Failed' => ['App\Listeners\CheckOldPassword'],

4:創建功能public function handle(Failed $event){}

5:手動檢查登錄事件。

0

可能嘗試使用認證的看起來像這樣由默認的中間件:

<?php 

namespace App\Http\Middleware; 

use Closure; 
use Illuminate\Support\Facades\Auth; 

class RedirectIfAuthenticated 
{ 
    /** 
    * Handle an incoming request. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @param \Closure $next 
    * @param string|null $guard 
    * @return mixed 
    */ 
    public function handle($request, Closure $next, $guard = null) 
    { 
     if (Auth::guard($guard)->check()) { 
      return redirect('/home'); 
     } 

     return $next($request); 
    } 
} 

嘗試檢查用戶是否已驗證,那麼如果不打電話,將您的密碼功能,並在數據庫中檢查。