config auth.php,Laravel basic-auth

问题

I want to use basic.auth for my web page but authentication donst work

routes.php

admin - authentication

Route::get('admin', array('before' => 'auth.basic', function()

{

return 'Top secret';

}));

create - create test user

Route::get('create', function()

{

$user = new User;

$user->email = 'test@test.com';

$user->username = 'test';

$user->password = Hash::make('password');

$user->save();

});

config

app/config/app - has defined key (that created Laravel installation)

app/config/auth - has defined model (User) and table (users)

filters.php

auth.basic

Route::filter('auth.basic', function()

{

return Auth::basic();

});

test

I call /create to create User test@test.com:password

Here is users table after:

b382719424dba83759b84b61c9d2d2d8.png

Then I call /admin to login

20e3eda154e5e5b6f823ab78df956cde.png

But it doesnt let me in. After Login - it just clear inputs. After Cancel - it return Invalid credentials..

User model

I tried implement UserInterface

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;

}

}

Problem solved

I had typo in User model return $this->passsword; There is 3 s.

Now I use default Laravel User model.

回答1:

Ensure that in app/config/auth.php - driver is set to eloquent.

You may also need to implement the UserInterface interface (class User extends Eloquent implements UserInterface) - then you'll need to include the methods in your model:

/**

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

}

来源:https://stackoverflow.com/questions/17447617/laravel-basic-auth

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值