Reputation: 4944
Today I restore my Macbook OS Yosemite and I forgot to backup my .env
file, so I lost my APP_KEY
.
Now all my paswords not work anymore and I understand that. So I do that:
php artisan key:generate
Then I update all passwords using this code:
Route::get('/', function () {
$users = new Project\DB\User;
$users->update(['password' => Hash::make('newPasswordHere')]);
});
But when I try to update an user using the system and I change the password, I can't login. That's the code of 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?
PHP 5.6.11 (cli) (built: Jul 19 2015 15:15:07)
nginx version: nginx/1.8.0
If you need more information, tell me please.
Upvotes: 3
Views: 1664
Reputation: 4944
I do not believe that was the problem, but I must tell them the real cause and solution:
At the beginning of the project I was set a mutator to password attribute.
This mutator in turn was already encrypting the password (yes ... I know, I do not believe I did not see it).
public function setPasswordAttribute($value)
{
$this->attributes['password'] = bcrypt($value);
}
Finally, the solution of the problem was not encrypt the password on the controller:
if ($request->has('password')) {
$user->password = $request->get('password');
}
Sorry and thank you for your time!
Upvotes: 1