【问题标题】:auth()->attempt() in Laravel 5.5 did'nt work properlyLaravel 5.5 中的 auth()->attempt() 不能正常工作
【发布时间】:2018-01-01 02:55:50
【问题描述】:

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

这是我的控制器。

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');

这是我的数据库

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

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

【问题讨论】:

  • 您的密码没有经过哈希处理,它永远不会起作用。
  • 所以我需要散列我的密码配置?
  • 您的密码需要使用hash::make方法存储在数据库中。
  • 它有效!谢谢@Ohgodwhy

标签: php laravel authentication login laravel-5.5


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      只需在注册方法中添加 Hash::make 方法即可,谢谢!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-27
        • 2017-03-10
        • 2014-06-20
        • 1970-01-01
        • 2015-06-10
        • 1970-01-01
        • 2014-12-17
        • 1970-01-01
        相关资源
        最近更新 更多