[英]Why I keep getting 401 Unauthorized error when trying to login with Laravel basic Auth?
I need an explanation for this behavior on Laravel's basic authentication.我需要对 Laravel 基本身份验证的这种行为进行解释。 First thing I have a seeder class with factory file to generate users.
首先我有一个带有工厂文件的播种机 class 来生成用户。
$factory->define(User::class, function (Faker $faker) {
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
];
});
I tried to log in using the user details extracted from my database using PHPMyAdmin我尝试使用 PHPMyAdmin 从我的数据库中提取的用户详细信息登录
Here's my authentication middleware call:这是我的身份验证中间件调用:
Also, I tried to create a new user directly via PHPMyAdmin, But whenever I tried to log in I got the 401 Unauthorized
另外,我尝试通过 PHPMyAdmin 直接创建一个新用户,但是每当我尝试登录时,我都会得到
401 Unauthorized
I'm building an API and trying to log in using Postman and I have a clean Laravel 7 installation, and yes I know I'm entering the email as username and the password. I'm building an API and trying to log in using Postman and I have a clean Laravel 7 installation, and yes I know I'm entering the email as username and the password.
You should do your factory using 'password' => Hash::make('password')
你应该使用
'password' => Hash::make('password')
来做你的工厂
As you can see in the doc, https://laravel.com/docs/7.x/hashing#introduction Laravel is using BCrypt by default to generate the password hash正如您在文档中看到的那样, https://laravel.com/docs/7.x/hashing#introduction Laravel 默认使用 BCrypt 生成密码 Z0800FC577294C34E05B28AD283934
If you really need to create the Hash manually, head over to https://bcrypt-generator.com/ and copy the hash generated there (by default Laravel uses 12 rounds) If you really need to create the Hash manually, head over to https://bcrypt-generator.com/ and copy the hash generated there (by default Laravel uses 12 rounds)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.