This question already has an answer here:

I want update customer password by customer repository.

Currently I am updating customer password like this

    ->save($customer,$this->encryptor->getHash($password, true));

\Magento\Customer\Api\CustomerRepositoryInterface $customerRepository

but it is not working for me.

Any one know how to update customer password?

marked as duplicate by 7ochem, Manoj Deswal, Jai, Piyush, Dhiren Vasoya Apr 6 '18 at 9:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


I have completed by below code

public function __construct(
    \Magento\Customer\Model\CustomerRegistry $customerRegistry,
    \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
    $this->_customerRegistry   = $customerRegistry;
    $this->_CustomerRepositoryInterface = $customerRepository;

Use below code in my custom function for update customer data

$customer = $this->_CustomerRepositoryInterface->getById($id);
$customerSecure = $this->_customerRegistry->retrieveSecureData($customer->getId());
$customerSecure->setPasswordHash($this->encryptor->getHash($password, true));
  • What we need to pass in $id for this first line? $customer = $this->_CustomerRepositoryInterface->getById($id); – Jimit Bhavsar Sep 28 '18 at 14:11
  • need to pass customer id? – Jimit Bhavsar Sep 28 '18 at 14:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.