Laravel: What is “remember_token” in the “users” DB table?

前端 未结 4 525
春和景丽
春和景丽 2021-01-31 08:22

Is it safe to use the remember_token in the users table for authenticating the user into the application?

What is the purpose of this token? Currently, I\'m

4条回答
  •  面向向阳花
    2021-01-31 08:54

    Even if this an old question, I wanted to present an option not use the token if you don't need it (e.g. have no remember me option on your site).

    Instead of adding a dummy column to your users table you can just prevent Auth::logout() from setting it.

    Just add this to your User model (works as of Laravel 5.6):

    public function save(array $options = array()) {
        if(isset($this->remember_token))
            unset($this->remember_token);
    
        return parent::save($options);
    }
    

    This removes the 'remember_token' column just before the model gets saved and thus preventing an error to be risen because of the non-existant column.

提交回复
热议问题