I want to use basic.auth for my web page but authentication donst work
admin - authenticationRoute::get('admin', array('before' => 'auth.basic', function()
{
return 'Top secret';
}));
create - create test userRoute::get('create', function()
{
$user = new User;
$user->email = '[email protected]';
$user->username = 'test';
$user->password = Hash::make('password');
$user->save();
});
app/config/app - has defined key (that created Laravel installation)app/config/auth - has defined model (User) and table (users)auth.basicRoute::filter('auth.basic', function()
{
return Auth::basic();
});
I call /create to create User [email protected]:password
Here is users table after:

Then I call /admin to login

But it doesnt let me in. After Login - it just clear inputs. After Cancel - it return Invalid credentials..
I tried implement 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;
}
}
I had typo in User model return $this->passsword; There is 3 s.
Now I use default Laravel User model.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With