How to reconfigure the APP_KEY of a Laravel 5.1 application

0

Today I restored my Macbook Pro because I had some incompatibilities with the El Capitan (beta) .

During this process, I forgot to back up the .env file of my project, so I was not able to login to the application (because of APP_KEY ).

Obviously I understand the reason, but what I did not discover was how to solve it.

Initially I tried the following:

php artisan key:generate

With this I generated a new APP_KEY right? So now I need to update all the passwords:

Route::get('/', function () {
    $users = new Project\DB\User;
    $users->update(['password' => Hash::make('newPasswordHere')]);
});

Ok, I updated and I can login, great right? Not! When I try to update a password on the system (/ admin), I can not log in after that.

Below is the code for the update($id) method:

$user = User::getById($id);

$user->role_id = $request->get('role_id');
$user->first_name = $request->get('first_name');
$user->last_name = $request->get('last_name');
$user->email = $request->get('email');

if ($request->has('password')) {
    $user->password = Hash::make($request->get('password'));
}

$user->active = $request->get('active');
$user->update();

What am I doing wrong?

My setup

  • Macbook Pro - Yosemite
  • PHP-FPM - PHP 5.6.11 (cli) (built: Jul 19 2015 15:15:07)
  • Nginx - nginx version: nginx/1.8.0

If you need more information let me know.

    
asked by anonymous 27.07.2015 / 13:31

1 answer

0

I can not believe the problem was this, but I must tell you the real cause and solution:

At the beginning of the project I had a mutator for the password attribute.

This mutator in turn was already encrypting the password (yes ... I know, I do not believe it either.)

public function setPasswordAttribute($value)
{
    $this->attributes['password'] = bcrypt($value);
}

Anyway, the solution to the problem was not to encrypt the password in the controller:

if ($request->has('password')) {
    $user->password = $request->get('password');
}

Thanks in advance for your time!

    
27.07.2015 / 13:49