【问题标题】:How to authenticate with Sentinel by username?如何通过用户名向 Sentinel 进行身份验证?
【发布时间】:2015-07-22 14:30:44
【问题描述】:

我正在使用 Cartalyst 的 Sentinel 进行 PHP 身份验证。传统的身份验证方式是使用电子邮件和密码,我们可以在他们的文档中看到:

$credentials = [
    'email'    => 'john.doe@example.com',
    'password' => 'password',
];

Sentinel::authenticate($credentials);

库提供的默认users表是这样的:

id | email | password | permissions |last_login | first_name | created_at | updated_at

我想添加一个 username 列并通过 usernamepassword 使用 Sentinel 进行身份验证。有可能吗?

【问题讨论】:

    标签: php authentication login sentinel


    【解决方案1】:

    您可以在此处修改此示例

    http://naomiaro.com/2015/07/08/multiple-login-attributes-with-sentinel-and-laravel/

    在您的用户模型中,您必须覆盖属性 $loginNames,并将用户名添加到属性 $fillable。

    use Cartalyst\Sentinel\Users\EloquentUser as SentinelUser;
    
    class User extends SentinelUser {
    
        protected $fillable = [
            'email',
            'username',
            'password',
            'last_name',
            'first_name',
            'permissions',
        ];
    
        protected $loginNames = ['username'];
    
    }
    
    Sentinel::authenticate([
        'username'    => 'fake',
        'password' => 'password'
    ]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-08
      • 2019-09-18
      • 2022-01-03
      • 2020-07-19
      • 2016-04-16
      • 2012-11-23
      • 2017-07-03
      • 1970-01-01
      相关资源
      最近更新 更多