在Laravel 5.5中,auth() - > attempt()没有正常工作

问题描述 投票:0回答:3

我已经创建了一个没有哈希的简单登录,以便更容易理解,但我的auth总是抛出错误信息,我正在搜索解决方案,但仍然有相同的结果。

这是我的控制器。

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;

//Class needed for login and Logout logic
use Illuminate\Foundation\Auth\AuthenticatesUsers;

//Auth facade
use Auth;

class AuthController extends Controller
{
    public function __construct()
    {
      $this->middleware('guest', ['except' => ['auth']]);
    }

    public function auth()
    {
       if (auth()->check()) 
       {
         return redirect()->userDash();
       }
       else 
       {
         if (auth()->attempt([
                'email'     => request('email'),
                'password'  => request('password')
            ]))
         {
            return redirect()->userDash();
         }
         else
         {
           return back()->withErrors([
           'message' => 'Please Check Your Credentials !'
          ]);
         }             
       }
    }

这是路线

Route::POST('/login', 'AuthController@auth');

这是我的数据库

enter image description here

这是我调试输入电子邮件和密码时的结果

enter image description here

我认为一切都是正确的,如果登录方法的代码错误,可能需要进行一些更正。谢谢。

php laravel authentication login laravel-5.5
3个回答
2
投票

您必须使用bcrypt()Hash::make()方法加密密码,并在登录控制器中使用Illuminate\Support\Facades\Auth;。更多details


2
投票

Laravel使用bcrypt()方法加密密码。注册用户时需要使用bcrypt方法。像:bcrypt(request('password'))


0
投票

只需在注册方法中添加Hash :: make方法,它就可以了,谢谢!

© www.soinside.com 2019 - 2024. All rights reserved.