if(Auth::attempt(['username' => Input::get('username'), 'password' => Input::get('password')])){
return Auth::user();
}
return 'Failed!';
That is the problematic code and I am sure the problem is in the Auth::attempt line. I have found other topics about this, but neither of them had a solution. I.e.: https://laracasts.com/forum/?p=1314-laravel-from-scratch-authentication-lesson-help/0
My User model implements the UserInterface and I have also put use Illuminate\Support\Facades\Auth as Auth; in the controller, in case it is not recognized in the Auth::attempt part. Nevertheless, it doesn't work both with and without the use ....
I tried also with
Auth::attempt(Input::only('username', 'password'))
And I always get to the Failed! part...
The password is stored as hashed string in the DB, and when I debug with the following:
echo Input::get('username') . "____" . Input::get('password');
die();
I get the correct results. So, I can't think of anything else than that the problem must occur in the ::attempt function.
Any sussgestions?
**Update: ** The User model
use Illuminate\Auth\UserTrait; use Illuminate\Auth\UserInterface; use Illuminate\Auth\Reminders\RemindableTrait; use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
protected $fillable = [
'username',
'password',
'email'
];
public static $rules = [
'username' => 'required',
'password' => 'required',
'email' => 'required'
];
public static $error_messages;
/**
* The database table used by the model.
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
* @var array
*/
protected $hidden = ['password', 'remember_token'];
public static function isValid($input)
{
$validation = Validator::make($input, static::$rules);
if ($validation->passes()) return true;
static::$error_messages = $validation->messages();
return false;
}
Usermodel? - lukasgeiter