0

I really try to debug my issues on my own before I bring them here, but I seriously cannot find a solution to my laravel auth problem, though it seems to be a common issue.

My authentication will not login. It always returns false and I don't understand why.

I am trying to login using auth:attempt but its not working . Going always in else condition.

When auth attempt getting success its automatically going in if condition otherwise other condition

 <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Hash; use App\Http\Controllers\Redirect; use App\User; use Illuminate\Support\Facades\Auth; class AdminCreateLogin extends Controller { public function addAdmin(Request $request) { $name = $request->username; $password = $request->password; $password = Hash::make($password); $email = $request->email; $user= new User; $user->name = $name; $user->password = $password; $user->email = $email; $user->save(); } public function adminLogin(Request $request) { $email = $request->email; $password1 = $request->password; $password = bcrypt($password1); //$password = hash:make($password1); $userdata = array( 'email' => $email, 'password' => $password ); if(Auth::attempt($userdata)) { echo "login"; die; return redirect('/admin/post/list'); } else { echo "login not"; die; return back()->with('error',"Invalid Login"); } } } 

Please help me in this.

2
  • 1
    Auth::attempt() need raw password so no need to bcrypt () it Commented Oct 6, 2020 at 5:30
  • the plain text password is what is passed to attempt Commented Oct 6, 2020 at 5:37

1 Answer 1

1

You don't need bcrypt manually. https://laravel.com/docs/7.x/authentication#authenticating-users

$credentials = $request->only('email', 'password'); if (Auth::attempt($credentials)) { // Authentication passed... return redirect()->intended('dashboard'); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.