01gurl
01gurl

Reputation: 21

laravel auth::attempt() always return false

I tried to create a login system but Auth::attempt always return false even though I entered the correct data. I have hashed the password when registering. Here's my code

LoginController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
    //
    public function index()
    {
        return view('login.index', [
            "title" => "Login",
            "active" => "login",
        ]);
    }

    public function authenticate(Request $request)
    {
        $credentials = $request->validate([
            'email' => 'required|email:dns',
            'password' => 'required',
        ]);

        // dd(Auth::attempt($credentials));

        if (Auth::attempt($credentials)) {
            $request->session()->regenerate();
            return redirect()->intended('/dashboard');
        }

        return back()->with('loginError', 'These credentials do not match our records.');
    }
}

Upvotes: 1

Views: 869

Answers (1)

JS TECH
JS TECH

Reputation: 1583

Did you hashed the password using bcrypt($password) helper method or Illuminate\Support\Facades\Hash::make($password) class method ?

Or,

May be there is another code for hashing in Model, Controller, Scope, Event, Listener, Observer, etc. file. Please check every file which is recently created and related to User Model.

Read more about hashing, if you need docs: Hashing

Upvotes: 0

Related Questions