Laravel 5 db:种子用户名和密码,但不在登录时进行身份验证

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31114918/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:51:20  来源:igfitidea点击:

Laravel 5 db:seed the username and password, but not authenticating on login

authenticationlaravellaravel-5

提问by Tarunn

I have implemented Database seeder to seed in user (default) credentials.

我已经实现了数据库播种器以在用户(默认)凭据中播种。

Admin::create(['name' => 'Super Admin', 'email' => '[email protected]', 'password' => bcrypt('password') ]);

After running seed, I got success message. But when I try to make login, it says your credential are not matching. Is there any particular reason for this. Can't we seed user data with bcrypt??

运行种子后,我收到成功消息。但是当我尝试登录时,它说您的凭据不匹配。这有什么特别的原因吗。我们不能用 bcrypt 播种用户数据吗??

回答by P??

If we talk about the default AuthControllerof Laravel 5 obviously no you can't:

如果我们谈论AuthControllerLaravel 5的默认设置,显然你不能:

protected function create(array $data)
{
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
    ]);
}

If you have a look at the create()function you can see that the data submitted as password is automatically bcrypted. So if you bcrypt the password too it is bcrypted a second time.

如果您查看该create()函数,您可以看到作为密码提交的数据是自动 bcrypted 的。因此,如果您也 bcrypt 密码,它会再次 bcrypted。

回答by jenecro

I inserted the data into my user table from my seeder as so:

我将数据从播种机插入到我的用户表中,如下所示:

DB::table('users')->insert([
        'Email' => '[email protected]',
        'Name' => 'Administrator',
        'PhoneNumber' => '00000',
        'Password' => bcrypt('P@ssw0rd'),
        'isEnabled' => true,
        'isAdmin' => true
        ]);

This works for me and I am able to log in while using the default auth controller.

这对我有用,我可以在使用默认身份验证控制器时登录。