Here is the basic idea --
You need to override controller using <preference>
in your module.
vendor/magento/module-customer/Controller/AccountResetPasswordPost.php
in this file you need to put below code in execute
function-
public function execute()
{
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
$resetPasswordToken = (string)$this->getRequest()->getQuery('token');
$customerId = (int)$this->getRequest()->getQuery('id');
$password = (string)$this->getRequest()->getPost('password');
$passwordConfirmation = (string)$this->getRequest()->getPost('password_confirmation');
if ($password !== $passwordConfirmation) {
$this->messageManager->addError(__("New Password and Confirm New Password values didn't match."));
$resultRedirect->setPath('*/*/createPassword', ['id' => $customerId, 'token' => $resetPasswordToken]);
return $resultRedirect;
}
if (iconv_strlen($password) <= 0) {
$this->messageManager->addError(__('Please enter a new password.'));
$resultRedirect->setPath('*/*/createPassword', ['id' => $customerId, 'token' => $resetPasswordToken]);
return $resultRedirect;
}
try {
$customerEmail = $this->customerRepository->getById($customerId)->getEmail();
$this->credentialsValidator->checkPasswordDifferentFromEmail($customerEmail, $password);
$this->accountManagement->resetPassword($customerEmail, $resetPasswordToken, $password);
$this->session->unsRpToken();
$this->session->unsRpCustomerId();
$this->messageManager->addSuccess(__('You updated your password.'));
/* start code to customer login and redirect to dashboard */
// use dependency injection instead of object manager
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customer = $objectManager->create('Magento\Customer\Model\Customer')->loadByEmail($customerEmail);
$this->session->setCustomerAsLoggedIn($customer);
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setUrl('url_to_customer_dashboard');
return $resultRedirect;
/* end code*/
$resultRedirect->setPath('*/*/login');
return $resultRedirect;
} catch (InputException $e) {
$this->messageManager->addError($e->getMessage());
foreach ($e->getErrors() as $error) {
$this->messageManager->addError($error->getMessage());
}
} catch (\Exception $exception) {
$this->messageManager->addError(__('Something went wrong while saving the new password.'.$exception->getMessage()));
}
$resultRedirect->setPath('*/*/createPassword', ['id' => $customerId, 'token' => $resetPasswordToken]);
return $resultRedirect;
}
Extra Notes:-
(a) use dependency injection instead of object manager.
(b) use this link to know how to use preference.
I hope it would help.