Skip to content

Commit 202bf5a

Browse files
committed
Merge remote-tracking branch 'tango/MAGETWO-93628' into tango-PR-04
2 parents 1acce35 + a74b0c1 commit 202bf5a

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,6 @@ public function initiatePasswordReset($email, $template, $websiteId = null)
624624
* @param string $rpToken
625625
* @throws ExpiredException
626626
* @throws NoSuchEntityException
627-
*
628627
* @return CustomerInterface
629628
* @throws LocalizedException
630629
*/
@@ -703,7 +702,12 @@ public function resetPassword($email, $resetToken, $newPassword)
703702
$customerSecure->setRpTokenCreatedAt(null);
704703
$customerSecure->setPasswordHash($this->createPasswordHash($newPassword));
705704
$this->destroyCustomerSessions($customer->getId());
706-
$this->sessionManager->destroy();
705+
if ($this->sessionManager->isSessionExists()) {
706+
//delete old session and move data to the new session
707+
//use this instead of $this->sessionManager->regenerateId because last one doesn't delete old session
708+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
709+
session_regenerate_id(true);
710+
}
707711
$this->customerRepository->save($customer);
708712

709713
return true;
@@ -1564,6 +1568,7 @@ private function getEmailNotification()
15641568

15651569
/**
15661570
* Destroy all active customer sessions by customer id (current session will not be destroyed).
1571+
*
15671572
* Customer sessions which should be deleted are collecting from the "customer_visitor" table considering
15681573
* configured session lifetime.
15691574
*

app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,8 +1238,7 @@ public function testInitiatePasswordResetEmailReminder()
12381238

12391239
$storeId = 1;
12401240

1241-
mt_srand(mt_rand() + (100000000 * (float)microtime()) % PHP_INT_MAX);
1242-
$hash = md5(uniqid(microtime() . mt_rand(0, mt_getrandmax()), true));
1241+
$hash = hash('sha256', microtime() . random_int(PHP_INT_MIN, PHP_INT_MAX));
12431242

12441243
$this->emailNotificationMock->expects($this->once())
12451244
->method('passwordReminder')
@@ -1263,8 +1262,7 @@ public function testInitiatePasswordResetEmailReset()
12631262
$templateIdentifier = 'Template Identifier';
12641263
$sender = 'Sender';
12651264

1266-
mt_srand(mt_rand() + (100000000 * (float)microtime()) % PHP_INT_MAX);
1267-
$hash = md5(uniqid(microtime() . mt_rand(0, mt_getrandmax()), true));
1265+
$hash = hash('sha256', microtime() . random_int(PHP_INT_MIN, PHP_INT_MAX));
12681266

12691267
$this->emailNotificationMock->expects($this->once())
12701268
->method('passwordResetConfirmation')
@@ -1288,8 +1286,7 @@ public function testInitiatePasswordResetNoTemplate()
12881286
$templateIdentifier = 'Template Identifier';
12891287
$sender = 'Sender';
12901288

1291-
mt_srand(mt_rand() + (100000000 * (float)microtime()) % PHP_INT_MAX);
1292-
$hash = md5(uniqid(microtime() . mt_rand(0, mt_getrandmax()), true));
1289+
$hash = hash('sha256', microtime() . random_int(PHP_INT_MIN, PHP_INT_MAX));
12931290

12941291
$this->prepareInitiatePasswordReset($email, $templateIdentifier, $sender, $storeId, $customerId, $hash);
12951292

@@ -1610,7 +1607,7 @@ function ($string) {
16101607
$this->customerSecure->expects($this->once())->method('setRpTokenCreatedAt')->with(null);
16111608
$this->customerSecure->expects($this->any())->method('setPasswordHash')->willReturn(null);
16121609

1613-
$this->sessionManager->expects($this->atLeastOnce())->method('destroy');
1610+
$this->sessionManager->method('isSessionExists')->willReturn(false);
16141611
$this->sessionManager->expects($this->atLeastOnce())->method('getSessionId');
16151612
$visitor = $this->getMockBuilder(\Magento\Customer\Model\Visitor::class)
16161613
->disableOriginalConstructor()

0 commit comments

Comments
 (0)