Learn to Encrypt Customer Password in Magento

Unfortunately, since we have to integrate our another customized system x in magento, we have to find a way to sync it's users and passwords fields.

Which we have achieved by:

Assumption:
1.) You must have a deployed magento system which you can access (because magento's libraries will be use in this solution). Specifically, core/encryption and core/helper/data.

To call the magento api in another system, paste the following lines:

require_once 'app/Mage.php'; //change the directory accordingly :D
umask(0);
$app = Mage::app('default');


And add more lines:

$obj = Mage::getModel('core/encryption'); //instantiate the core encryption mode,
$helper = Mage::helper('core'); //instantiate the core helper,
$obj->setHelper($helper); //set the encryptions helper,
$enc_pwd = $obj->getHash($pwd, 2); //get the password's hash


BTW, for info, you can check if you have entered a correct password by adding this line:

echo $obj->validateHash($pwd, $enc_pwd);


If it echoes 1 then the password is correct. Try it, it works for me.

6 Comments

  1. Very helpful - thanks! I was trying to figure out how to do this and your code was exactly what I was looking for.

    ReplyDelete
  2. Very nice!
    Thanks!

    U help a brazilian guy!

    ReplyDelete
  3. Lovely Article....Perfect...
    Thanks Dear

    ReplyDelete
  4. Thank you very much. I used this code-snippet to realize a customer-import extension.

    ReplyDelete
  5. Thanks. It works fine for me.

    ReplyDelete

Post a Comment

Post a Comment

Previous Post Next Post
NERV Open Source

Building production Spring Boot systems?

Explore NERV — open-source Java libraries for audit trails, persistence, exception handling, and reliable event-driven architecture.

Explore NERV on GitHub →