I use Hash to bcrypt password in my seeder, and in my controller, i use Auth to check request from client. but it always return false, i dont know why.
this is all of code:
-
my HomeController:
public function login(Request $request) { $username = $request->input('username'); $password = Hash::make($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); } } }
-
my seeder has:
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") ]);
-
my model User:
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', ];
}
and my router has:
Route::post('/login', 'HomeController@login');
but when i request with info of seeder, Auth::attempt () always return false:
(1/1) BadMethodCallException Method handle does not exist. in Macroable.php line 74 i dont know why it export this error, please help!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire