What do you mean? You can't convert a hash to another hash
Jun 9, 2017
16
Level 2
How can I change Md5 Passwords to Bcrypt in Laravel 5.4?
I have tried several solutions online but nothing has worked.
I am pretty lost.
Level 8
@sufuninja to add more context to my previous answer and to go along with what @Snapey just said, I went to the file Snapey referenced (vendor/laravel/framework/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php), copied the login function from it, pasted it into app/Http/Controllers/Auth/LoginController.php and made the following modifications there.
/**
* Overwrite default login method to help migrate viewers to using
* bcrypt encrypted passwords
*/
public function login(Request $request)
{
$this->validateLogin($request);
// If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and
// the IP address of the client making these requests into this application.
if ($this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
// check if account logging in for first time
// check against old md5 password, if correct, create bcrypted updated pw
$user = User::where('email', $request->input('email'))->first();
if (!$user->password_updated) {
if ($this->sqlPassword($request->input('password')) === $user->old_password) {
$user->password = bcrypt($request->input('password'));
$user->password_updated = 1;
$user->save();
} else {
return $this->sendLoginResponse($request);
}
}
if ($this->attemptLogin($request)) {
return $this->sendLoginResponse($request);
}
// If the login attempt was unsuccessful we will increment the number of attempts
// to login and redirect the user back to the login form. Of course, when this
// user surpasses their maximum number of attempts they will get locked out.
$this->incrementLoginAttempts($request);
return $this->sendFailedLoginResponse($request);
}
Please or to participate in this conversation.