我正在构建一个系统,当用户首次使用 Facebook 登录时,他无需提供密码。所以我尝试使用来自 Facebook 的凭据让他登录。
Sentry::authenticate($credentials, false);
上面的命令总是需要输入密码。如何在不询问用户密码的情况下登录用户?
最佳答案
在 Sentry 中,您可以通过两种不同的方式登录:
1) 当您在登录表单上输入密码时,您告诉 Sentry 找到用户并检查密码以验证身份并同时登录他/她:
// Set login credentials
$credentials = array(
'email' => Input::get('email'),
'password' => Input::get('password'),
);
// Try to authenticate the user
$user = Sentry::authenticate($credentials, false);
2) 当用户通过其他方式(如 OAuth)进行身份验证时,您只需要强制其登录到您的系统:
// Find the user using the user id or e-mail
$user = Sentry::findUserById($userId);
// or
$user = Sentry::findUserByLogin($email);
// and
// Log the user in
Sentry::login($user, false);
您可以选择其中之一,不必同时使用两者。
3) 作为第三个示例,假设您有一个旧用户数据库并且您的密码使用 MD5 进行哈希处理:
// Find the user
$user = Sentry::findUserByLogin($email);
// Check the password
if ($user->password !== md5(Input::get('password'))
{
Redirect::back()->withMessage('Password is not correct.');
}
// And, if password is correct, force the login:
Sentry::login($user, false);
关于php - Sentry on Laravel 4. 无密码社交认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20667004/