如何通过用户名与哨兵验证? [英] How to authenticate with Sentinel by username?

查看:365
本文介绍了如何通过用户名与哨兵验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Sentinel通过Cartalyst与PHP认证。验证传统的方法是通过使用电子邮件和密码,我们可以阅读他们的文档:

I'm using Sentinel by Cartalyst for authentication with PHP. The traditional way to authenticate is by use of e-mail and password, as we can read in their documentation:

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

Sentinel::authenticate($credentials);

默认的用户的库提供的表是这样的:

The default users table provided by the library is like that:

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

我要添加的用户名的列,并使用Sentinel通过的用户名的和的密码的身份验证。这可能吗?

I want to add a username column and authenticate using Sentinel by username and password. Is it possible?

推荐答案

您可以在这里修改此示例

You can modify this example here

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

在您的用户模型,你必须重写属性​​$ loginNames,并添加用户名到属性$可填写。

In your Users model you must override the attribute $loginNames, and add username to the attribute $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'
]);

这篇关于如何通过用户名与哨兵验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆