laravel-8 - Laravel 8 Auth:这些凭据与我们的记录不匹配
问题描述
我想建立旧系统的新版本。旧版本在核心php中。我已经导入了旧版本的数据库,我可以从数据库中获取所有用户信息,但是当我无法通过从数据库中获取的相同信息登录时。
这是我的模型
<?php
namespace App\Models\SYS;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
use Illuminate\Support\Facades\Hash;
class AdminUser extends Authenticatable
{
use HasFactory;
use Notifiable;
use HasApiTokens;
use HasApiTokens;
protected $fillable = ['appID', 'companyID', 'sysAdminFirstName', 'sysAdminLastName', 'sysAdminUserName', 'sysAdminPassword', 'sysAdminActive', 'appActive'];
protected $table = '_sys_admin_users';
protected $hidden = [
'sysAdminPassword',
];
}
这是我的控制器代码
public function loginform(Request $request)
{
if (Auth::attempt(['sysAdminUserName' => $request->sysAdminUserName, 'sysAdminPassword' => $request->sysAdminPassword])) {
return 'authenticate';
}
else{
return response()->json(['message' => 'Username or Password does not match'], 401);
}
}
我的配置/auth.php
<?php
return [
/*
|--------------------------------------------------------------------------
| 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' => 'passport',
'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\Models\SYS\AdminUser::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,
'throttle' => 60,
],
],
/*
|--------------------------------------------------------------------------
| Password Confirmation Timeout
|--------------------------------------------------------------------------
|
| Here you may define the amount of seconds before a password confirmation
| times out and the user is prompted to re-enter their password via the
| confirmation screen. By default, the timeout lasts for three hours.
|
*/
'password_timeout' => 10800,
];
解决方案
推荐阅读
- c - 即使我在两个循环之后都释放了嵌套的while循环中的内存泄漏
- python - 如何打印列表中字典之间的所有唯一键?
- r - 闪亮的 Flexdasboard 反应式仪表未更新
- laravel - 无法使用 yajra 数据表显示 html 元素
- sql - 在 pandas 或 SQL 中将数字月份更改为名称月份
- r - 检查是否在R中的嵌套函数中使用了某个函数
- python - Python - 数组中某个元素的所有外观的索引数组
- drools - 为什么当多个 KieBase 并行执行时 Drools 会执行不正确的规则?
- c# - MongoDB C# 驱动程序 - 更新嵌入式文档数组中的所有字段
- reactjs - 在 React 上编写的两段代码之间有什么区别,其中包含 useEffect 钩子和一些异步内容?