1

My auth function is always returning false in my UserController function, here is my controller function.

public function postSignin(Request $request)
{
    $userdata = array(
        'email'      => $request->input('email'),
        'password'   => $request->input('password')
    );

    if (Auth::attempt($userdata))
    {
        return redirect()->route('user.profile');
    }
    else
    {
        return redirect()->back();
    }
}

and here is my route code

Route::post('/signin', [
    'uses' => 'UserController@postSignin' , 'as' => 'user.signin'
]);

When I enter the credentials, the if part of auth is not working and I am redirected to my page as instructed by the else condition...

2
  • Did you use php artisan make:auth for this? Commented Jul 22, 2016 at 14:10
  • This might be related to the user creation. Did you use Hash::make() when creating user? Commented Jul 22, 2016 at 15:39

1 Answer 1

2

You may be saving your users passwords as plain text into the database, because when using the Auth::attempt() function laravel automatically hashes the password to compare. Make sure when inserting you properly hash the password with the bcrypt() helper function. The only other possibility I can think of is if your sure your putting in the right password or username?

Example of bcrypt when creating a new user:

User::create([
    "username" => $username,
    "password" => bcrypt($password);
]);

Hope this helps!

Sign up to request clarification or add additional context in comments.

1 Comment

I am using bcrypt function while creating user , still its not working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.