简体   繁体   English

为什么我在尝试使用 Laravel 基本身份验证登录时不断收到 401 Unauthorized 错误?

[英]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.

相关问题 在 Laravel 7 中获得“401”未经授权的错误 - Getting "401" Unauthorized error in Laravel 7 Phonegap错误:401未经授权 - 在Phonegap中使用基本身份验证的Rest API - Phonegap Error : 401 Unauthorized - consuming Rest API with Basic Auth in Phonegap 不断获得401个未经授权的“无效凭证” Laravel Passport - Keep getting 401 unauthorized 'invalid credentials' Laravel Passport Laravel | 领英登录-'401未经授权' - Laravel | LinkedIn Login - '401 Unauthorized' Laravel 6 护照中的未经授权的 401 错误 - Unauthorized 401 error in laravel 6 passport 为什么我在 Microsoft Graph API 调用中收到“401 Unauthorized”? - Why am I Getting "401 Unauthorized" for Microsoft Graph API Call? 当与CakePHP一起使用Auth组件时,我一直收到此错误。 为什么? - When using the Auth component with CakePHP, I keep getting this error. Why? Laravel 9:我尝试登录时出错(它没有)¿Auth::Login? - Laravel 9: error when i try to sign in (It doesnt) ¿Auth::Login? 基本的laravel身份验证无法登录 - Basic laravel auth cannot login 路由登录未定义,如果管理员用户当前未登录,我在尝试使页面重定向到登录时不断收到此错误 - Route login not defined, i keep getting this error when trying to make the page redirect to the login if the admin user is currently not logged in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM