0
votes

the Laravel Auth::attempt function fails always. But i can't find any other method to authenticate the user or the false code... I checked the Input from my Form with an echo in the following if condition ( else part, because the true condition never entered).

public function postSignIn(Request $request)
{
    $email=$request['email'];
    $password=$request['password'];
    $remember=$request['remember'];

   if(Auth::attempt(['email' => $email, 'password' => $password])){
        return redirect()->route('dashboardStart');
   }
        return redirect()->back();

}

The password is hashed by the normal laravel hash function and saved to the database.

$pw=Hash::make($pw1);

to store pw and email

   $user->Email=$email;
    $user->Password=$pw;
   //writes the data to the DB
    $user->save();

So, hope someone can help me.

EDIT 2:

Ok that's crazy... I changed the validation function and validate the email and password with the normal php function and the condition is true...

if(($email===$userDBEntry['Email'])&&password_verify($password,   $userDBEntry['Password'])){
        return redirect()->route('dashboardStart');
   }
        return redirect()->back();
3
What problem you are facing?Mayank Pandeyz
Please post the exact error message you are gettingMikkel
I don't get any error message. Only Auth:attempt returns allways falsetheface

3 Answers

0
votes

i think you are not taking inputs correctly request is not an array it's a function so call function to get input

public function postSignIn(Request $request)
{
   if(Auth::attempt( $request->only(['email','password']) ){
        return redirect()->route('dashboardStart');
   }
        return redirect()->back();

}
0
votes

Can you check what you get for $password and $email I agree with Sam, you should use methods of the Request object to access the attributes, such as

$email= $request->input('email');
$password= $request->input('password');

more about it in documentation.

EDIT: 2 more ideas on what to try... verify that you do have that user in the database (if it is not there, then there is a problem somewhere with saving/registration process)

try changing

$pw=Hash::make($pw1);
$user->Email=$email;
$user->Password=$pw;

to

$user->email=$email;
$user->password=$pw1;

And also verify that you are getting the $email and $pw (or $pw1) values as you expect them to be.

0
votes

You are using Illuminate\Http\Request and putting it in the function, postSignIn(Request $request).

The correct way to retrieve email/password from the Request object is to call $request->email instead of $request['email'] when you pass it to the Auth::attempt.


So:

$email=$request['email']; // make it $request->email $password=$request['password']; // make it $request->password $remember=$request['remember'];