Converting plain password in database to Laravel encrypted password

前端 未结 2 1133
走了就别回头了
走了就别回头了 2021-01-27 11:00

I have a table called \"users\" where I have username and password from my users.

The passwords are in plain text. Now I\'ve created a new site with Laravel 6.0 and Auth

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-27 11:20

    You have to create a function to update your database passwords to encrypted passwords first.

    Something like this on web.php, and visit /password-updator on browser

    Route::get('/password_updator', function() {
     $allusers = \DB::table('users')->get();
     foreach($users as $user) {
      $user->password = bcrypt($user->password);
      $user->save();
    }
    });
    

    Make sure yo backup your database before you proceed!

    Or you create a new column called password_hashed first onn users table and update it to experiment.

    https://laravel.com/docs/5.4/helpers#method-bcrypt

提交回复
热议问题