Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use separate password_resets_table for each #51

Closed
ankurk91 opened this issue Dec 28, 2016 · 4 comments
Closed

Use separate password_resets_table for each #51

ankurk91 opened this issue Dec 28, 2016 · 4 comments

Comments

@ankurk91
Copy link

This package uses same database table (password_resets) for each guard.

But there is problem using this -
Lets take an example :
There are two types of users

  • Admin
  • Customer

An admin can be a customer and a customer can be an admin. Same person have two different account but with same email address.
Now when that admin user make any password reset request, application will overwrite any existing (this can be himself as customer) request for same email address. This way the tokens gets lost and email link becomes invalid.

The possible solution is to use a separate table for each user type -

  • Create a new admin_password_resets table
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAdminPasswordResetsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('admin_password_resets', function (Blueprint $table) {
            $table->string('email')->index();
            $table->string('token')->index();
            $table->timestamp('created_at')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('admin_password_resets');
    }
}
  • Specify this table name in app/config/auth.php file
'passwords' => [
        'admins' => [
            'provider' => 'admins',
            'table' => 'admin_password_resets',
            'expire' => 60,
        ],

        'users' => [
            'provider' => 'users',
            'table' => 'password_resets',
            'expire' => 60,
        ],
    ],
  • That's it, Laravel will use this new table for admins password reset tokens from now
@Hesto
Copy link
Owner

Hesto commented Dec 28, 2016

Thats good idea thanks. i will add it to the next version.

@ankurk91
Copy link
Author

ankurk91 commented Jan 2, 2017

P.S.
Laravel 5.4 going to remove password reset table, see
laravel/laravel@master...tillkruss:passwords

@Hesto
Copy link
Owner

Hesto commented Jan 4, 2017

Oh.. but why? Maybe there will by any artisan command.

@ankurk91
Copy link
Author

ankurk91 commented Jan 5, 2017

checkout this PR
laravel/framework#16850

Hesto added a commit that referenced this issue Jan 8, 2017
Issue #51 : Use separate password_resets_table for each
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants