Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 Auth:attempt not working

I am having hard time working with Laravel 4 Auth::attempt method , followed the right documentation, read couple of SO threads but still i am not able to get it working.

$userData = array('email' => '[email protected]','password' => 'admin');
if(Auth::attempt($userData)){
    // redirect
}
else{
   echo 'Invalid';
}

And it returns Invalid everytime

Now i am not sure what is the actual reason.

In my config/auth.php i have following

<?php

   return array(
/*
|--------------------------------------------------------------------------
| Default Authentication Driver
|--------------------------------------------------------------------------
|
| This option controls the authentication driver that will be utilized.
| This drivers manages the retrieval and authentication of the users
| attempting to get access to protected areas of your application.
|
| Supported: "database", "eloquent"
|
*/

'driver' => 'eloquent',

/*
|--------------------------------------------------------------------------
| Authentication Model
|--------------------------------------------------------------------------
|
| When using the "Eloquent" authentication driver, we need to know which
| Eloquent model should be used to retrieve your users. Of course, it
| is often just the "User" model but you may use whatever you like.
|
*/

'model' => 'User',

/*
|--------------------------------------------------------------------------
| Authentication Table
|--------------------------------------------------------------------------
|
| When using the "Database" authentication driver, we need to know which
| table should be used to retrieve your users. We have chosen a basic
| default value but you may easily change it to any table you like.
|
*/

'table' => 'users',

/*
|--------------------------------------------------------------------------
| Password Reminder Settings
|--------------------------------------------------------------------------
|
| Here you may set the settings for password reminders, including a view
| that should be used as your password reminder e-mail. You will also
| be able to set the name of the table that holds the reset tokens.
|
*/
'reminder' => array(
    'email' => 'emails.auth.reminder', 'table' => 'password_reminders',
),
 );
 ?>
like image 504
Aman Virk Avatar asked Jun 04 '13 11:06

Aman Virk


People also ask

Why is HTTP Basic authentication not working in my Laravel application?

By default, the auth.basic middleware will assume the email column on your users database table is the user's "username". If you are using PHP FastCGI and Apache to serve your Laravel application, HTTP Basic authentication may not work correctly.

How do I tell Laravel if a user has confirmed their password?

If the password is valid, we need to inform Laravel's session that the user has confirmed their password. The passwordConfirmed method will set a timestamp in the user's session that Laravel can use to determine when the user last confirmed their password.

What are the different Laravel authentication packages?

These packages are Laravel Breeze, Laravel Jetstream, and Laravel Fortify. Laravel Breeze is a simple, minimal implementation of all of Laravel's authentication features, including login, registration, password reset, email verification, and password confirmation.

When should I use Laravel sanctum for authentication?

In general, Sanctum should be preferred when possible since it is a simple, complete solution for API authentication, SPA authentication, and mobile authentication, including support for "scopes" or "abilities". If you are building a single-page application (SPA) that will be powered by a Laravel backend, you should use Laravel Sanctum.


1 Answers

Make sure that your password field in your db has space for 64 characters. varchar(64)

The hash needs 64 characters and you won't get an error from laravel if your hashed password is truncated on insertion (and therefore not able to ever validate a password positively).

like image 61
Isabell Knauer Avatar answered Oct 24 '22 21:10

Isabell Knauer