php - Sentry on Laravel 4. 无密码社交认证

标签 php laravel laravel-4 cartalyst-sentry

我正在构建一个系统,当用户首次使用 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/

相关文章:

javascript - 倒数计时器问题

php - 如何在 Laravel 中的 SELECT 语句后插入记录时应用 'ON CONFLICT' 条件?

php - Laravel Eloquent : how to filter multiple and/or criteria single table

php - 使用布局模板的 flash 消息重定向回来

laravel - 在 Laravel 查询范围内查询相关模型

Laravel 4 : default format error messages

php - 修复 PHP 的表输出

PHP 处理可能未设置的变量的最佳方法是什么?

PHP Echo 的 Javascript 使用

php - Laravel 通过引用事件订阅者传递数组