I am trying to import customers using .csv
file. I did it using data flow profiles in magento. I have list of customers and passwords but I have passwords in string format. How to convert string password into password_hash
?
4 Answers
First you need to convert all the password to hash password. then on the sheet use password_hash instead of password for set password.
Use magento core helper class for generate hash_password:
Mage::helper('core') ->getHash('YOUR_PASSWORD', Mage_Admin_Model_User::HASH_SALT_LENGTH);
I needed to solve a similar problem to the OP, however, I needed to do it in a stand-alone script outside of Magento, so I extracted the important parts of the app into a single class for easy use.
Use it like:
$newPw = 'thisisatest'
$newPwHash = (new Magento_Admin_Password_Hasher())->generateHash($newPw);
echo $newPwHash;
Output: fa3e2266de47f6284fed4664896435a0:kVqArQN8pRtvoBROR99xAOpLbUmnwzJo
PHP class:
<?php
class Magento_Admin_Password_Hasher {
// From app/code/core/Mage/Core/Helper/Data.php
const CHARS_LOWERS = 'abcdefghijklmnopqrstuvwxyz';
const CHARS_UPPERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const CHARS_DIGITS = '0123456789';
// From app/code/core/Mage/Admin/Model/User.php
const HASH_SALT_LENGTH = 32;
// Our own function to tie it all together with sane defaults.
function generateHash($password)
{
return $this->getHash($password, self::HASH_SALT_LENGTH);
}
// From app/code/core/Mage/Core/Helper/Data.php
public function getRandomString($len, $chars = null)
{
if (is_null($chars)) {
$chars = self::CHARS_LOWERS . self::CHARS_UPPERS . self::CHARS_DIGITS;
}
for ($i = 0, $str = '', $lc = strlen($chars)-1; $i < $len; $i++) {
$str .= $chars[mt_rand(0, $lc)];
}
return $str;
}
// From app/code/core/Mage/Core/Model/Encryption.php
public function getHash($password, $salt = false)
{
if (is_integer($salt)) {
$salt = $this->/*_helper->*/getRandomString($salt);
}
return $salt === false ? $this->hash($password) : $this->hash($salt . $password) . ':' . $salt;
}
// From app/code/core/Mage/Core/Model/Encryption.php
public function hash($data)
{
return md5($data);
}
}
Magento 1.x uses below encryption scheme for hashing passwords
md5(salt.password):salt
Example:
Let say your salt value is = Stack88135
And your chosen password is = P@SS!2020
then putting it all together
md5(Stack88135.P@SS!2020):Stack88135
so the resultant hashed password would be
9d15c6206d90f9a7fdbaf2c179c40bc4:Stack88135
string password_hash ( string $password , integer $algo [, array $options ] )
Referrence http://php.net/manual/en/function.password-hash.php
-
-
Use it like this echo password_hash("rasmuslerdorf", PASSWORD_DEFAULT)."\n"; Commented Oct 29, 2015 at 6:13
-
3
-
Check this out stackoverflow.com/questions/31831142/… Commented Oct 29, 2015 at 6:33