【问题标题】:HTTP basic auth is not workingHTTP 基本身份验证不起作用
【发布时间】:2014-01-22 09:26:56
【问题描述】:

我正在使用 Laravel 4.1 创建一个 api。对于身份验证,我想使用 Laravel Basic auth。每次我填写输入字段时,它都不让我进入。它只是清除输入并再次弹出表单。我不确定我做错了什么。我没有使用迁移来创建用户表。这只是一条基本路线:

Route::get('admin', function()
{
    return "authenticated";

})->before('auth.basic');

这是我的过滤器:

Route::filter('auth.basic', function()
{
    return Auth::basic('username');
});

这是我的用户模型:

 <?php
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('password', 'pivot');

    /**
     * @var array
     */
    protected $guarded = array('id', 'created_at', 'updated_at', 'is_admin');

    protected $fillable = array('username', 'password', 'name_first', 'name_middle', 'name_last', 'email', 'address', 'city', 'state', 'zip_code', 'country', 'phone', 'title', 'profile_image', 'status');
    /**
     * @var array
     */
    public static $rules = array();


    /**
     * 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;
    }

    /**
     * Get the e-mail address where password reminders are sent.
     *
     * @return string
     */
    public function getReminderEmail()
    {
        return $this->email;
    }

}

【问题讨论】:

  • @yannis 你能解决我的问题吗?

标签: php laravel-4


【解决方案1】:

你为什么不试试

Route::get('admin', array( 'before' => 'auth.basic' ,function()
{
    return "authenticated";
}));

您的密码需要在您的数据库中进行哈希处理。

【讨论】:

  • 你能检查你的代码吗?您的代码在 'do' => function() 上有语法错误
  • @user2293111 对不起,我没有。看看现在能不能用。您确定输入正确的用户名、密码吗?
  • 是的,用户名和密码正确。有什么办法可以调试吗?
  • 我的意思是你的数据库里面有吗?密码是hashed吗?
  • 是的,问题解决了。密码需要经过哈希处理。谢谢
猜你喜欢
  • 2014-12-31
  • 1970-01-01
  • 1970-01-01
  • 2016-03-31
  • 1970-01-01
  • 2014-09-06
  • 2016-01-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多