gpt4 book ai didi

php - Laravel 4 授权 :attempt not working

转载 作者:可可西里 更新时间:2023-11-01 12:40:53 25 4
gpt4 key购买 nike

我在使用 Laravel 4 Auth::attempt 方法时遇到了困难,遵循了正确的文档,阅读了几个 SO 线程,但我仍然无法让它工作。

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

每次都返回无效

现在我不确定真正的原因是什么。

在我的 config/auth.php 中有以下内容

<?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',
),
);
?>

最佳答案

确保您的数据库中的密码字段有 64 个字符的空间varchar(64)

散列需要 64 个字符,如果你的散列密码在插入时被截断(因此无法正确验证密码),你不会从 laravel 收到错误。

关于php - Laravel 4 授权 :attempt not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16916765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com