Auth:attempt始终返回false
我已经检查了列名'password'的拼写是否正确,并且在将用户添加到数据库之前我对密码进行了哈希处理,因为尝试将对密码进行哈希处理并针对数据库中的哈希字符串检查哈希密码。 还要确保口才确实适用于所需的用户表。 尝试向用户模型添加实现Authenticateable的工具,但无效。
RegisterController
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
用户模型-当前用户模型
class User extends Authenticatable{
protected $table = 'users';
public $timestamps = false;
protected $attributes = [ 'rate' => 0];
protected $fillable = ['name', 'email', 'password'];
protected $visible = ['name', 'email', 'rate'];
}
登录控制器-自动生成,ofc使用AuthenticatesUsers类,而我对它们都没有感动
class LoginController extends Controller
{
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
表结构为
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email',100)->unique();
$table->double('rate');
$table->string('password');
});
config / auth.php是
返回[
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session", "token"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
],
],
];
我使用了auth:make命令,因此大部分代码都是自动生成的
当我使用xdebug调试并抛出dd命令时,所有从tryLogin中获得的信息都是假的,尝试也返回假的。
edit-表已更改为用户,并在创建方法上尝试使用Hash :: make代替,但仍然得到错误响应
编辑2-出于某种奇怪的原因,Hash:Check现在返回true,但是尝试仍然返回false。
编辑3-尝试仅用于调试,处理登录的功能为:
public function login(Request $request)
{
$this->validateLogin($request);
// If the class is using the ThrottlesLogins trait, we can
automatically throttle
// the login attempts for this application. We'll key this by the
username and
// the IP address of the client making these requests into this
application.
if ($this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
if ($this->attemptLogin($request)) {
return $this->sendLoginResponse($request);
}
// If the login attempt was unsuccessful we will increment the
number of attempts
// to login and redirect the user back to the login form. Of
course, when this
// user surpasses their maximum number of attempts they will get
locked out.
$this->incrementLoginAttempts($request);
return $this->sendFailedLoginResponse($request);
}
编辑5-路线列表: