2017-04-02 95 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); 
    } 
} 

尝试检查用户是否已验证,那么如果不打电话,将您的密码功能,并在数据库中检查。