Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpgradeCustomerPasswordObserver.php
Go to the documentation of this file.
1 <?php
8 
13 
15 {
21  protected $encryptor;
22 
26  private $customerRegistry;
27 
31  private $customerRepository;
32 
38  public function __construct(
40  CustomerRegistry $customerRegistry,
41  CustomerRepositoryInterface $customerRepository
42  ) {
43  $this->encryptor = $encryptor;
44  $this->customerRegistry = $customerRegistry;
45  $this->customerRepository = $customerRepository;
46  }
47 
54  public function execute(\Magento\Framework\Event\Observer $observer)
55  {
56  $password = $observer->getEvent()->getData('password');
58  $model = $observer->getEvent()->getData('model');
59  $customer = $this->customerRepository->getById($model->getId());
60  $customerSecure = $this->customerRegistry->retrieveSecureData($model->getId());
61 
62  if (!$this->encryptor->validateHashVersion($customerSecure->getPasswordHash(), true)) {
63  $customerSecure->setPasswordHash($this->encryptor->getHash($password, true));
64  $this->customerRepository->save($customer);
65  }
66  }
67 }
$customer
Definition: customers.php:11
$customerRepository
__construct(EncryptorInterface $encryptor, CustomerRegistry $customerRegistry, CustomerRepositoryInterface $customerRepository)
$customerRegistry
Definition: customers.php:12