CheckCustomerPassword.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\CustomerGraphQl\Model\Customer;
  8. use Magento\Customer\Model\AuthenticationInterface;
  9. use Magento\Framework\Exception\InvalidEmailOrPasswordException;
  10. use Magento\Framework\GraphQl\Exception\GraphQlAuthenticationException;
  11. /**
  12. * Check customer password
  13. */
  14. class CheckCustomerPassword
  15. {
  16. /**
  17. * @var AuthenticationInterface
  18. */
  19. private $authentication;
  20. /**
  21. * @param AuthenticationInterface $authentication
  22. */
  23. public function __construct(
  24. AuthenticationInterface $authentication
  25. ) {
  26. $this->authentication = $authentication;
  27. }
  28. /**
  29. * Check customer password
  30. *
  31. * @param string $password
  32. * @param int $customerId
  33. * @throws GraphQlAuthenticationException
  34. */
  35. public function execute(string $password, int $customerId)
  36. {
  37. try {
  38. $this->authentication->authenticate($customerId, $password);
  39. } catch (InvalidEmailOrPasswordException $e) {
  40. throw new GraphQlAuthenticationException(
  41. __('The password doesn\'t match this account. Verify the password and try again.')
  42. );
  43. }
  44. }
  45. }