---
title: "How To Programmatically Change Customer Password  In Magento 2"
url: "https://dolphinwebsolution.com/how-to-programmatically-change-customer-password-in-magento-2"
date: "2021-12-19T13:50:42+05:30"
modified: "2023-08-24T09:20:22+05:30"
author:
  name: "Jigar Patel"
categories:
  - "Magento"
word_count: 340
reading_time: "2 min read"
summary: "Password is a unique key that customers must use to access their accounts in your store, Changing password in Magento is not a big deal if you are logged in to the My Account area/Admin dashboard. ..."
description: "Password is a unique key that customers must use to access their accounts in your store, Changing password in Magento is not a big deal if you are logged in ..."
keywords: "Change Customer Password,customer password,customer repository magento 2,programmatically, Magento"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Create Admin Theme in Magento 2"
    url: "https://dolphinwebsolution.com/how-to-create-admin-theme-in-magento-2"
  - title: "How to Customize Email Templates in Magento 2"
    url: "https://dolphinwebsolution.com/how-to-customize-email-templates-in-magento-2"
  - title: "How to use slick carousel slider in Magento 2"
    url: "https://dolphinwebsolution.com/how-to-use-slick-carousel-slider-in-magento-2"
---

# How To Programmatically Change Customer Password In Magento 2

_Published: December 19, 2021_  
_Author: Jigar Patel_  

![](https://dolphinwebsolution.com/wp-content/uploads/2023/02/How-To-Programmatically-Change-Customer-Password-In-Magento-2-1024x536.png)

Password is a unique key that customers must use to access their accounts in your store, Changing password in Magento is not a big deal if you are logged in to the My Account area/Admin dashboard. I am talking about changing a customer’s password using a program. The below code will show you how to programmatically change a customer password without validating an old password.

Magento 2 new customer account is created via sign up, Also customer registration is possible via the admin panel. But, you can easily reset the password in your account.

**Read This:** [How to Add Customer Attribute Programmatically in Magento 2](https://dolphinwebsolution.com/how-to-add-customer-attribute-in-magento-2)

Programmatically change customer password create a PHP file in Magento root directory using following code. Do not forget to specify the customer id and password you want to set inside the code.

## Step To Programmatically Change Customer Password in Magento 2:

```
<?php
use Magento\Framework\AppInterface;
ini_set('display_errors', 1);
try {
    require '../app/bootstrap.php';
} catch (\Exception $e) {
    echo $e->getMessage();
    exit;
}
try{
    $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
    $objectManager = $bootstrap->getObjectManager();
    $appState = $objectManager->get('\Magento\Framework\App\State');

    $customerRepositoryInterface = $objectManager->get('\Magento\Customer\Api\CustomerRepositoryInterface');
    $customerRegistry = $objectManager->get('\Magento\Customer\Model\CustomerRegistry');
    $encryptor = $objectManager->get('\Magento\Framework\Encryption\EncryptorInterface');
    $appState->setAreaCode('frontend');

    $customerId = 11; // here assign your customer id
    $password = "Dolphin123"; // set your custom password
    $customer = $customerRepositoryInterface->getById($customerId);
    $customerSecure = $customerRegistry->retrieveSecureData($customerId);
    $customerSecure->setRpToken(null);
    $customerSecure->setRpTokenCreatedAt(null);
    $customerSecure->setPasswordHash($encryptor->getHash($password, true));
    $customerRepositoryInterface->save($customer);
    echo 'Successfully Changes Your Password.';
}
catch(\Exception $e){
    print_r($e->getMessage());
}
```

**customerRepositoryInterface** is an instance of \\Magento\\Customer\\Api\\CustomerRepositoryInterface
**customerRegistry** is an instance of \\Magento\\Customer\\Model\\CustomerRegistry
**encryptor** is an instance of \\Magento\\Framework\\Encryption\\EncryptorInterface

Successfully executing this script your customer will be able to log in to their account using **“Dolphin123”** password.

This way we can update customer password in Magento2.

hope this instruction will be helpful for you.


---

_View the original post at: [https://dolphinwebsolution.com/how-to-programmatically-change-customer-password-in-magento-2](https://dolphinwebsolution.com/how-to-programmatically-change-customer-password-in-magento-2)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-09-15 15:48:11 UTC_  
