gpt4 book ai didi

laravel - Auth::attempt () 在 Laravel 5.5 中总是返回 false

转载 作者:行者123 更新时间:2023-12-01 12:09:27 25 4
gpt4 key购买 nike

我在我的seeder中使用Hash来bcrypt密码,在我的 Controller 中,我使用Auth来检查来自客户端的请求,但它总是返回false,我不知道为什么。

这是代码:

我的家庭 Controller :

    public function login(Request $request)
{
$username = $request->input('username');
$password = $request->input('password');

if( Auth::attempt(['mssv' =>$username, 'pass' =>$password])) {
$success = new MessageBag(['successlogin' => 'welcome']);
return view('welcome')->withErrors($success);
} else {
$errors = new MessageBag(['errorlogin' => 'Login fail']);
return redirect()->back()->withInput()->withErrors($errors);
}
}
}

我的播种机有:

    DB::table('sinhvien')->insert([
'hoten' => 'Nguyễn Ngọc Anh Thư',
'mssv' =>'DH51400668',
'pass' =>Hash::make('DH51400668'),
'created_at'=>date("Y-m-d H:i:s"),
'updated_at'=>date("Y-m-d H:i:s")
]);

我的模型用户:

    <?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
use Notifiable;

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $table='sinhvien' ;
protected $fillable = [
'mssv', 'hoten', 'pass',
];

/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'pass', 'remember_token',
];
}

我的路由器有:

Route::post('/login', 'HomeController@login'); 

但是当我请求播种机的信息时,Auth::attempt () 总是返回 false。

最佳答案

从密码捕获字段中删除 Hash::make。当您使用 Auth::attempt 时,它会默认获取哈希值并通过 DB 进行搜索。

尝试

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

if( Auth::attempt(['mssv' =>$username, 'pass' => $password])) { # remove quotes

How to prevent SQL injection in Laravel?

关于laravel - Auth::attempt () 在 Laravel 5.5 中总是返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53259093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com