5

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?

3

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);
1

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);
    }
}
-3
string password_hash ( string $password , integer $algo [, array $options ] )

Referrence http://php.net/manual/en/function.password-hash.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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