Magento - Customer password encryption

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:

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
$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.
Magento - Customer password encryption Magento - Customer password encryption Reviewed by czetsuya on Friday, August 21, 2009 Rating: 5


that san jose guy said...

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

Filipe said...

Very nice!

U help a brazilian guy!

Anonymous said...

Lovely Article....Perfect...
Thanks Dear

Martin said...

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

viettq said...

Thank you, very helpful!

Chamath said...

Thanks. It works fine for me.

Powered by Blogger.