1
votes

I am using laravel 5.0. I want login using auth laravel, but I only need to input the username when login (no need email and/or password). And I have changed the code into these below.

In my LoginController:

public function getLogin(){
    if(!Auth::check()) {
        return view('auth.login');  
    }
    else{
        return redirect('home');
    }
}

public function postLogin(){

    Auth::attempt([
        'USER_NAME' => Input::get('username')
    ]);

    return redirect('home');
}

In my User model:

<?php namespace App;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract {
use Authenticatable, CanResetPassword;

protected $table = 'MS_USER_ROLE';

}

And I have got an error:

ErrorException in EloquentUserProvider.php line 111: Undefined index: password

Do you know how to solve this?

2
You'll have to edit the Trait it uses. - Daan
what do you mean 'Trait it uses'? - hendraspt
If you don't know what that means you will not be able to edit it. Can't you just add a password to the attempt method and fake it? - Daan
yeah you're right, I did that in my previous project. This will be my last option if I'm not find any solution. - hendraspt

2 Answers

1
votes

Check the documentation for Laravel Authentication.

You want to use the Auth::login() method to explicitly log them in.

public function postLogin()
{
    $user = User::where('USER_NAME', '=', Input::get('username'))->firstOrFail();
    Auth::login($user);

    return redirect('home');
}
0
votes

Just log them in manually if you're authenticating by username:

public function postLogin()
{
    $user = User::whereUsername(request('username'))->firstOrFail():

    Auth::login($user);

    return redirect('home');
}

https://laravel.com/docs/5.2/authentication#authenticating-users