Importing customers into magento with existing passwords

Importing customers into magento with existing passwords

August 3, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Importing customers into magento with existing passwords

Importing Customers into Magento with Existing Passwords

The Challenge: Incompatible Password Hashes Between Virtuemart and Magento

When migrating from Virtuemart to Magento, one of the most common challenges lies in the handling of customer passwords. This is due to the fact that both platforms use different algorithms for password hashing.

Virtuemart uses a simple md5($password.$salt) hash, while Magento employs a more complex md5($salt.$password). This discrepancy causes issues when trying to authenticate users with their existing Virtuemart passwords in the new Magento environment.

Understanding the Password Hashing Difference

Let’s break down the two hashing methods:

Virtuemart Hashing

Virtuemart generates a hash by concatenating the user’s plaintext password and a salt, then applies the md5 function. The resulting string is used as the hashed password.

Example:

  • Plaintext Password: mysecretpassword
  • Salt: AuHg2mCXUhViqKYCLtFco22rmUCDwIFI
  • Virtuemart Hash: c957d358c8a79e66af10086b53b5a069

Magento Hashing

Magento reverses the operation, concatenating the salt before the plaintext password. It also uses a fixed-length random string as the salt.

Example:

  • Plaintext Password: mysecretpassword
  • Salt (Fixed Length Random String): h884259517c36cacfc3f7670beb02a98
  • Magento Hash: 8b57f1e871b7cdc7bfc259d5329bc411:h884259517c36cacfc3f7670beb02a98

A Partial Solution: Checking the Core Hashing Method

The provided code snippet attempts to solve this issue by checking if a given password matches either the Magento or Virtuemart hashing format. It uses a switch statement based on the count of elements in the hashed string.

public function validateHash($password, $hash)
{
    $hashArr = explode(':', $hash);
    switch (count($hashArr)) {
        case 1:
            return $this->hash($password) === $hash;
        case 2:
            return $this->hash($hashArr[1] . $password) === $hashArr[0];
    }
}

This approach works for Magento’s native user management but fails when handling Virtuemart passwords due to the different hashing format.

A Comprehensive Solution: Checking Both Hashing Methods

To accommodate both password formats, we need to modify the validateHash function. Here’s a more robust solution:

public function validateHash($password, $hash)
{
    // Attempt to match using Magento's hash format
    if ($this->matchMagentoFormat($password, $hash)) {
        return true;
    }

    // If not matched, attempt Virtuemart format
    return $this->matchVirtuemartFormat($password, $hash);
}

private function matchMagentoFormat($password, $hash)
{
    $hashArr = explode(':', $hash);

    if (count($hashArr) === 2 && strlen($hashArr[1]) === 32) {
        return $this->hash($hashArr[1] . $password) === $hashArr[0];
    }

    return false;
}

private function matchVirtuemartFormat($password, $hash)
{
    $hashArr = explode(':', $hash);

    if (count($hashArr) === 2 && strlen($hashArr[1]) > 32) {
        return $this->hash($password . $hashArr[1]) === $hashArr[0];
    }

    return false;
}

This updated function first attempts to match the password using Magento’s hash format. If it fails, it then tries to match the Virtuemart format.

The matchMagentoFormat and matchVirtuemartFormat helper functions check for the specific characteristics of each platform’s hashing method—32 characters for Magento salt and more than 32 characters for Virtuemart salt.

Conclusion

Migrating customer passwords from Virtuemart to Magento requires a careful consideration of the different password hashing formats used by both platforms. The provided solution demonstrates how to validate user credentials against both hashing methods, enabling seamless authentication for users with existing Virtuemart passwords in your new Magento environment.

Remember that security is paramount when handling sensitive data like passwords. Always ensure you’re following best practices and using secure hashing algorithms.

For more in-depth guides on Magento development, consider visiting LaravelCompany. They offer a range of resources to help you make the most out of your Magento projects.

Customers Import/Export Errors

Our network