Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

329
Visualizações
Laravel 5 authentication without remember_token

I am using an existing database, and I'm not allowed to modify the tables, so adding a remember_token is not an option, but without it I'm unable to login. When I try to login Laravel does check the credentials and returns whether they match the records, but it only refreshes the page. I am pretty sure the remember_token is the cause since I've encountered this problem before, but this time I can't add a column to my users table.

Is there a way to use the out-of-the-box authentication without the remember_token?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

In your User model add:

  /**
   * Overrides the method to ignore the remember token.
   */
  public function setAttribute($key, $value)
  {
    $isRememberTokenAttribute = $key == $this->getRememberTokenName();
    if (!$isRememberTokenAttribute)
    {
      parent::setAttribute($key, $value);
    }
  }

Credits: https://laravel.io/forum/05-21-2014-how-to-disable-remember-token

over 4 years ago · Santiago Trujillo Relatório

0

Since Laravel v5.3.27 you can also disable the remember me functionality by setting the $rememberTokenName to false in your User model.

class User extends Authenticatable
{
    use Notifiable;


    protected $rememberTokenName = false;

    // ...
}

source: this commit

over 4 years ago · Santiago Trujillo Relatório

0

In order to really disable the "remember me" functionality and to be sure the remember_token field is not used, add the following code to the boot method of App\Providers\AuthServiceProvider.

Auth::provider('eloquent', function($app, array $config)
{
  return new class($app['hash'], $config['model']) extends \Illuminate\Auth\EloquentUserProvider
  {
    public function retrieveByToken($identifier, $token)
    {
      return null;
    }

    public function updateRememberToken(\Illuminate\Contracts\Auth\Authenticatable $user, $token)
    {
      //Do nothing
    }
  };
});

assuming a default Laravel setup, the code above will work instantly.

Off course, it can be improved by defining the custom user provider in a seperate file instead of using a anonymous class.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda