A
A
Alexander2018-11-18 20:47:58
1C-Bitrix
Alexander, 2018-11-18 20:47:58

How to transfer users from Magento CMS with their passwords?

It is necessary to transfer the list of users from Magento to Bitrix. There is a CSV file with a list of users downloaded from the database. I would like to transfer users with old passwords. To do this, you need to get its hash from the string with the encrypted password and then save it in Bitrix.
The catch is that I don’t know by what principle Magento encodes passwords, where is the password hash itself in the string, and where are the additional characters (“salt”) that can be trimmed?
Bitrix encodes the password in md5 and then adds “salt” to the received string, maybe Magento has the same principle. Tell me by what principle in Magento the hash of passwords is formed for users.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Petrov, 2018-11-19
@sergoslav_0

If we are talking about Magento1, then the validation function is in Mage_Core_Model_Encryption:

/**
     * Hash a string
     *
     * @param string $data
     * @return string
     */
    public function hash($data)
    {
        return md5($data);
    }

    /**
     * Validate hash against hashing method (with or without salt)
     *
     * @param string $password
     * @param string $hash
     * @return bool
     * @throws Exception
     */
    public function validateHash($password, $hash)
    {
        $hashArr = explode(':', $hash);
        switch (count($hashArr)) {
            case 1:
                return hash_equals($this->hash($password), $hash);
            case 2:
                return hash_equals($this->hash($hashArr[1] . $password),  $hashArr[0]);
        }
        Mage::throwException('Invalid hash.');
    }

That is, if the password is presented as two hashes separated by a comma, then the first is a salt, and the second is an md5 hash. Otherwise it's just an md5 hash.
The salt is generated randomly for each user, so if you have a case with salt, then most likely you will have to finish the Bitrix code so that such passwords continue to work. (Although I have never dealt with Bitrix, maybe he does the same?)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question