'required', 'new_password' => 'required|strong_password|differs[password]', ]; if (! $this->validate($rules)) { return redirect() ->back() ->withInput() ->with('errors', $this->validator->getErrors()); } $validData = $this->validator->getValidated(); // check credentials with the old password if logged in without magic link $credentials = [ 'email' => auth() ->user() ->email, 'password' => $validData['password'], ]; $validCreds = auth() ->check($credentials); if (! $validCreds->isOK()) { return redirect()->back() ->with('error', lang('MyAccount.messages.wrongPasswordError')); } // set new password to user auth() ->user() ->password = $validData['new_password']; $userModel = new UserModel(); if (! $userModel->update(auth()->user()->id, auth()->user())) { return redirect() ->back() ->withInput() ->with('errors', $userModel->errors()); } // Success! return redirect() ->back() ->with('message', lang('MyAccount.messages.passwordChangeSuccess')); } }