Laravel 拉维尔基本认证

Laravel 拉维尔基本认证,laravel,laravel-4,Laravel,Laravel 4,我想对我的网页使用basic.auth,但身份验证不起作用 routes.php 管理-身份验证 创建-创建测试用户 配置 app/config/app-定义了键(创建了Laravel安装) app/config/auth-定义了模型(用户)和表(用户) filters.php auth.basic 测试 我调用/create创建用户test@test.com:密码 以下是用户表格: 然后我调用/admin登录 但它不让我进去。登录后-只需清除输入。取消后-返回无效凭据。 用户模型 我

我想对我的网页使用
basic.auth
,但身份验证不起作用

routes.php
管理
-身份验证
创建
-创建测试用户 配置
  • app/config/app
    -定义了
    键(创建了Laravel安装)
  • app/config/auth
    -定义了
    模型(
    用户
    )和
    表(
    用户
filters.php
auth.basic
测试 我调用
/create
创建用户
test@test.com
密码

以下是
用户
表格:

然后我调用
/admin
登录

但它不让我进去。登录后-只需清除输入。取消后-返回无效凭据。


用户模型 我尝试实现
UserInterface

<?php
use Illuminate\Auth\UserInterface;

class User extends Eloquent implements UserInterface {

    protected $table = 'users';

    /**
     * Get the unique identifier for the user.
     *
     * @return mixed
     */
    public function getAuthIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
        return $this->passsword;
    }
}

确保在app/config/auth.php-
driver
中设置为
elount

您可能还需要实现
UserInterface
接口(
class-User-extends-elount-implements-UserInterface
)-然后您需要在模型中包含以下方法:

/**
 * Get the unique identifier for the user.
 *
 * @return mixed
 */
public function getAuthIdentifier()
{
    return $this->getKey();
}

/**
 * Get the password for the user.
 *
 * @return string
 */
public function getAuthPassword()
{
    return $this->password;
}

1) 用户模型中是否有属性修饰符?-特别是对于密码(我有一个setter可以自动对给定值进行散列,所以我对密码进行了双重散列)和2)您是否尝试了另一个浏览器?@RobGordijn-1)用户模型只有-
类用户扩展雄辩的{}
。2) google chrome,Firefox你的用户模型实现了用户界面吗???看看Laravel 4附带的默认
user.php
模型。你到底在找什么?这是Laravel 4附带的默认模型:是的,它设置为eloquent |
auth.php
-
'driver'=>'eloquent'
您的答案非常好。。。我在
return$this->passsword中输入了错别字-3x
s
哦,很好,PEBKAC错误。是的,我们很难诊断:)
Route::filter('auth.basic', function()
{
    return Auth::basic();
});
<?php
use Illuminate\Auth\UserInterface;

class User extends Eloquent implements UserInterface {

    protected $table = 'users';

    /**
     * Get the unique identifier for the user.
     *
     * @return mixed
     */
    public function getAuthIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
        return $this->passsword;
    }
}
/**
 * Get the unique identifier for the user.
 *
 * @return mixed
 */
public function getAuthIdentifier()
{
    return $this->getKey();
}

/**
 * Get the password for the user.
 *
 * @return string
 */
public function getAuthPassword()
{
    return $this->password;
}