如何在登录时无需密码修改Laravel授权


How to modify Laravel Authorization without password when do login?

我使用的是laravel 5.0。我想使用auth laravel登录,但我只需要在登录时输入用户名(不需要电子邮件和/或密码)。我已将代码更改为以下代码:

在我的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');
}

在我的User模型:

<?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';
}

我得到了一个错误:

在EloquentUserProvider.php第111行出现ErrorException:未定义索引:password

你知道怎么解决这个吗?

查看Laravel认证的文档

您希望使用Auth::login()方法显式地登录它们。

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

如果你是通过用户名认证,只需手动登录:

public function postLogin()
{
    $user = User::whereUsername(request('username'))->firstOrFail():
    Auth::login($user);
    return redirect('home');
}

https://laravel.com/docs/5.2/authentication用户身份验证