简体   繁体   English

使用社交身份验证详细信息从内置登录系统登录

[英]Using social authenticaion details to login from built in login system

I have both the laravel built in and social authentication. 我既有内置的laravel也有社交认证。 Suppose if a user logs in using facebook, i store the user details such as fb_id , username , email etc. to the users table which is authenticable from built in login system.This way i can use laravel Auth . 假设如果用户使用Facebook登录,我fb_id用户详细信息(例如fb_idusernameemail等)存储到可从内置登录系统进行身份验证的users表中。这样,我可以使用laravel Auth

$fb_user = Socialite::driver('facebook')->user(); 
$user = User::firstOrCreate(['fb_id'=>$fb_user->id,'name' => $fb_user->name, 'email' => $fb_user->email]);
Auth::login($user, true);
return redirect('/');

Now, the users table have a user with username and password NULL. 现在,用户表具有一个用户名和密码为NULL的用户。 Couldn't anybody login with just username from built in login if no password validations are required? 如果不需要密码验证,没有人只能使用内置登录名中的用户名登录吗? OR what is wrong with my concept here? 或者我的概念有什么问题吗?

Couldn't anybody login with just username from built in login if no password validations are required? 如果不需要密码验证,没有人只能使用内置登录名中的用户名登录吗?

Yes Anybody can login. 是的,任何人都可以登录。

From the comments: 从评论:

Solution 1: 解决方案1:

Password should be hashed.Assuming empty passwords are allowed, they will hash to something that is not empty (for example, password_hash('',PASSWORD_DEFAULT); returns something like $2y$10$MD7HZwh9oki9U74Ta1/7OuDpYK8UXAFEufgMIeNazKSyv1xRabwqu‌​ ) Therefore there should be no real issue with this method. 密码应hashed.Assuming空密码是允许的,他们会出现乱码的东西,不为空(例如, password_hash('',PASSWORD_DEFAULT);返回类似$2y$10$MD7HZwh9oki9U74Ta1/7OuDpYK8UXAFEufgMIeNazKSyv1xRabwqu‌​ )因此应该不存在真正的这种方法的问题。

Solution 2: 解决方案2:

We should have a field to flag the user as being from a separate authentication source. 我们应该有一个字段来将用户标记为来自单独的身份验证源。 That way if anyone tries to login directly using those details you can ignore rows with that flag when checking credentials 这样,如果有人尝试使用这些详细信息直接登录,则在检查凭据时可以忽略带有该标志的行

Recently I got this same issue. 最近我遇到了同样的问题。 I recommend this: 我建议这样做:

When user choose social media to login into your website, create their account in your website using the information you got from the social media site after authentication, logged them into your website. 当用户选择社交媒体登录到您的网站时,使用从身份验证后从社交媒体网站获得的信息在您的网站中创建他们的帐户,然后将其登录到您的网站。 Now as soon as they login, show them a popup to set a password for their account . 现在,当他们登录时,向他们显示一个弹出窗口以为他们的帐户设置密码

Now on, then can use both Laravel built in and social authentication for login. 现在,可以同时使用内置的Laravel和社交身份验证进行登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM