php - How do I manually authenticate user in Laravel 5.4 -
i trying authenticate user in laravel 5.4, using attempt() able authenticate user, want check if user active or not , show custom message depending upon if user inactive different message , if username password different different message.
my authentication code :
public function checklogin(request $request) { $password = bcrypt($request->password); $userdata = user::where('email',$request->email)->where('password',$password)->first(); if($userdata!=null) { $credentials=array('email' => $request->input('email'),'password' => $request->input('password'),'status' => 'active'); if(auth::guard('users')->attempt($credentials)) return redirect()->intended('/dashboard'); else { mail::to($request->email)->send(new verifyuser($userdata)); return redirect('/')->with('error','your account unverified - check email account verification link'); } } else return redirect('/')->with('error','invalid username or password'); } here, first want check if login credentials correct or not, if invalid directly show error message "invalid username or password", if suppose login credentails correct, trying attempt login , if user inactive want show message "you need verify account" , if user active redirect user dashboard.
but in case not able authenticate user if bcrypt password , cross check password in db table.
there many ways this, since mentioned in comment interested in getting line 4 in code work
$userdata = user::where('email',$request->email)->where('password',$password); line above not work since bcrypt generates new hash doesn't match hashed password in database.
you can instead:
$userdata = user::where('email',$request->email)->first(); if ($userdata && hash::check($request->password, $userdata->password)) { // passwords match... }
Comments
Post a Comment