Skip to main content
Tweeted twitter.com/StackMagento/status/1564538434991144962
Became Hot Network Question
corrected spelling
Source Link
Ben
  • 141
  • 2
  • 18

}

}

Source Link
Ben
  • 141
  • 2
  • 18

Magento 2.4.4. password reset link always expired

After updating to Magento 2.4.4, clicking the "Set new password" link in the "Forgot password mail" send by the system the link always shows as expired?!

Setting of "Recovery Link Expiration Period (hours) = 2 hours"

Seems like a bug to me. Does anyone see what is wrong in native Magento CreatePassword.php for example? Replacing "token" with "amp;token" does not help (as suggested by some for earlier versions)

CreatePassword.php in vendor/magento/module-customer/Controller/Account is as follows in Magento 2.4.4:

  public function __construct(
    Context $context,
    Session $customerSession,
    PageFactory $resultPageFactory,
    AccountManagementInterface $accountManagement,
    ConfirmCustomerByToken $confirmByToken = null,
    GetCustomerByToken $getByToken = null,
    CustomerRepositoryInterface $customerRepository = null
) {
    $this->session = $customerSession;
    $this->resultPageFactory = $resultPageFactory;
    $this->accountManagement = $accountManagement;
    $this->confirmByToken = $confirmByToken
        ?? ObjectManager::getInstance()->get(ConfirmCustomerByToken::class);
    $this->getByToken = $getByToken
        ?? ObjectManager::getInstance()->get(GetCustomerByToken::class);
    $this->customerRepository = $customerRepository
        ?? ObjectManager::getInstance()->get(CustomerRepositoryInterface::class);

    parent::__construct($context);
}

/**
 * Resetting password handler
 *
 * @return Redirect|Page
 */
public function execute()
{
    $resetPasswordToken = (string)$this->getRequest()->getParam('token');
    $customerId = (int)$this->getRequest()->getParam('id');
    $isDirectLink = $resetPasswordToken != '';
    if (!$isDirectLink) {
        $resetPasswordToken = (string)$this->session->getRpToken();
        $customerId = (int)$this->session->getRpCustomerId();
    }

    try {
        $this->accountManagement->validateResetPasswordLinkToken($customerId, $resetPasswordToken);
        $this->confirmByToken->resetCustomerConfirmation($customerId);

        // Extend token validity to avoid expiration while this form is
        // being completed by the user.
        $customer = $this->customerRepository->getById($customerId);
        $this->accountManagement->changeResetPasswordLinkToken($customer, $resetPasswordToken);

        if ($isDirectLink) {
            $this->session->setRpToken($resetPasswordToken);
            $this->session->setRpCustomerId($customerId);
            $resultRedirect = $this->resultRedirectFactory->create();
            $resultRedirect->setPath('*/*/createpassword');

            return $resultRedirect;
        } else {
            /** @var Page $resultPage */
            $resultPage = $this->resultPageFactory->create();
            $resultPage->getLayout()
                       ->getBlock('resetPassword')
                       ->setResetPasswordLinkToken($resetPasswordToken)
                       ->setRpCustomerId($customerId);

            return $resultPage;
        }
    } catch (\Exception $exception) {
        $this->messageManager->addErrorMessage(__('Your password reset link has expired.'));
        /** @var Redirect $resultRedirect */
        $resultRedirect = $this->resultRedirectFactory->create();
        $resultRedirect->setPath('*/*/forgotpassword');

        return $resultRedirect;
    }
}

}