-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CC-26451: Password reset improvement (#10628)
CC-26451 Fixed Insecure Password Reset Workflow
- Loading branch information
Showing
10 changed files
with
269 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/Spryker/Zed/Customer/Business/Customer/Checker/PasswordResetExpirationChecker.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace Spryker\Zed\Customer\Business\Customer\Checker; | ||
|
||
use DateTime; | ||
use Generated\Shared\Transfer\CustomerErrorTransfer; | ||
use Generated\Shared\Transfer\CustomerResponseTransfer; | ||
use Orm\Zed\Customer\Persistence\SpyCustomer; | ||
use Spryker\Zed\Customer\CustomerConfig; | ||
|
||
class PasswordResetExpirationChecker implements PasswordResetExpirationCheckerInterface | ||
{ | ||
/** | ||
* @var \Spryker\Zed\Customer\CustomerConfig | ||
*/ | ||
protected CustomerConfig $customerConfig; | ||
|
||
/** | ||
* @param \Spryker\Zed\Customer\CustomerConfig $customerConfig | ||
*/ | ||
public function __construct(CustomerConfig $customerConfig) | ||
{ | ||
$this->customerConfig = $customerConfig; | ||
} | ||
|
||
/** | ||
* @param \Orm\Zed\Customer\Persistence\SpyCustomer$customerEntity | ||
* @param \Generated\Shared\Transfer\CustomerResponseTransfer $customerResponseTransfer | ||
* | ||
* @return \Generated\Shared\Transfer\CustomerResponseTransfer | ||
*/ | ||
public function checkPasswordResetExpiration( | ||
SpyCustomer $customerEntity, | ||
CustomerResponseTransfer $customerResponseTransfer | ||
): CustomerResponseTransfer { | ||
if (!$this->customerConfig->isCustomerPasswordResetExpirationEnabled()) { | ||
return $customerResponseTransfer | ||
->setIsSuccess(true); | ||
} | ||
|
||
/** @var \DateTime|string|null $restorePasswordDate */ | ||
$restorePasswordDate = $customerEntity->getRestorePasswordDate(); | ||
|
||
if (!$restorePasswordDate) { | ||
return $customerResponseTransfer; | ||
} | ||
|
||
if (is_string($restorePasswordDate)) { | ||
$restorePasswordDate = new DateTime($restorePasswordDate); | ||
} | ||
|
||
$expirationDate = clone $restorePasswordDate; | ||
$expirationDate->modify($this->customerConfig->getCustomerPasswordResetExpirationPeriod()); | ||
$now = new DateTime(); | ||
|
||
if ($now < $expirationDate) { | ||
return $customerResponseTransfer; | ||
} | ||
|
||
$customerErrorTransfer = (new CustomerErrorTransfer())->setMessage(CustomerConfig::GLOSSARY_KEY_CONFIRM_EMAIL_LINK_INVALID_OR_USED); | ||
|
||
return $customerResponseTransfer | ||
->setIsSuccess(false) | ||
->addError($customerErrorTransfer); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...pryker/Zed/Customer/Business/Customer/Checker/PasswordResetExpirationCheckerInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace Spryker\Zed\Customer\Business\Customer\Checker; | ||
|
||
use Generated\Shared\Transfer\CustomerResponseTransfer; | ||
use Orm\Zed\Customer\Persistence\SpyCustomer; | ||
|
||
interface PasswordResetExpirationCheckerInterface | ||
{ | ||
/** | ||
* @param \Orm\Zed\Customer\Persistence\SpyCustomer$customerEntity | ||
* @param \Generated\Shared\Transfer\CustomerResponseTransfer $customerResponseTransfer | ||
* | ||
* @throws \RuntimeException | ||
* | ||
* @return \Generated\Shared\Transfer\CustomerResponseTransfer | ||
*/ | ||
public function checkPasswordResetExpiration( | ||
SpyCustomer $customerEntity, | ||
CustomerResponseTransfer $customerResponseTransfer | ||
): CustomerResponseTransfer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.