skip to Main Content

I’m moving customers from CubeCart to Prestashop and would like to keep customers existing customer passwords.

I have found a contribution on the Prestashop forums that seems to do what I’m in need of, but, it is for ZenCart/OScommerce to Prestashop.
Therefore there is a slight difference in passsword structure that I need help with, please see below:

ZC/OSC
Format: 1 column, 32 alphanumeric characters + colon + 2 alphanumeric characters salt.
E.g.
e56d64755f66a86996b54114bb4102bf:08

CC
Format: 2 columns, 32 alphanumeric characters + a seperate 6-digit random salt.
E.g.
password: e56d64755f66a86996b54114bb4102bf
salt: 7pZcAF

So I’d please like abit of help adapting the below code to work with the 2 column CC password/salt:

// == BEGIN ZEN-CART / OSCOMMERCE TO PRESTASHOP PASSWORD INTEGRATION ==
// == BY João Cunha - [email protected]
// == @ 31/03/2012
// == USE AND MODIFY AT WILL
// == TESTED ON PRESTASHOP V1.4.7X
if (!$result) { //<- INVALID PRESTASHOP LOGIN, IT MAY BE A ZEN-CART / OSCOMMERCE     PASSWORD
//CHECK IF THE GIVEN EMAIL MATCHES A ROW IN OUR LEGACY TABLE AND RETRIEVES THE LEGACY     PASSWORD
$resultZC = Db::getInstance()->getRow('
SELECT `password`
FROM `zc_legacy_passwords`
WHERE `email` = ''.pSQL($email).''
AND `updated` = 0');

 if (!$resultZC)
return false; //<- EMAIL NOT FOUND IN NONE OF THE TABLES, SO IT IS AN INVALID LOGIN

//ENCRYPTS THE GIVEN PASSWORD IN ZEN-CART / OSCOMMERCE FORMAT
$salt = substr($resultZC['password'], strrpos($resultZC['password'],':')+1, 2);
$ZCpassword = md5($salt . $passwd) . ':' . $salt;

if ($ZCpassword != $resultZC['password'])
return false; //<- WRONG ZEN-CART/OSCOMMERCE PASSWORD GIVEN

//WE'LL UPDATE THE CUSTOMER TABLE WITH ITS PRESTASHOP ENCRYPTED PASSWORD...
Db::getInstance()->Execute('
                        UPDATE `'._DB_PREFIX_   .'customer`
                        SET `passwd` = ''.md5(pSQL(_COOKIE_KEY_.$passwd)).''
                        WHERE `email` = ''.pSQL($email).''');

//...AND FLAG IT AS UPDATED, SO THE NEXT TIME HE LOGS IN, HE WON'T ENTER THIS ROUTINE.
Db::getInstance()->Execute('
                UPDATE `zc_legacy_passwords`
                SET `updated` = 1
                WHERE `email` = ''.pSQL($email).''');

//USER IS AUTHENTICATED, OVERWRITE THE EMPTY $result VARIABLE
$result = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_ .'customer`
WHERE `active` = 1
AND `email` = ''.pSQL($email).''
AND `deleted` = 0
AND `is_guest` = 0');
}
// == END ZEN-CART / OSCOMMERCE TO PRESTASHOP PASSWORD INTEGRATION

This code will also updates the old salted password to the new Prestashop password type.

2

Answers


  1. this not important because this just check password :

    SELECT password FROM zc_legacy_passwords WHERE email =
    ”.pSQL($email).” AND updated = 0′);

    and then this code check the password in table database ZenCart/OScommerce you can remove or comment (just ignore)

    $salt = substr($resultZC[‘password’], strrpos($resultZC[‘password’],’:’)+1, 2);
    $ZCpassword = md5($salt . $passwd) . ‘:’ . $salt;

    if ($ZCpassword != $resultZC[‘password’]) return false;

    and this important because will store and modify password to prestashop (not need modif here)

    Db::getInstance()->Execute(‘
    UPDATE '._DB_PREFIX_ .'customer SET passwd =
    ”.md5(pSQL(_COOKIE_KEY_.$passwd)).” WHERE email =
    ”.pSQL($email).”’);

    ignore this:

    Db::getInstance()->Execute(‘ UPDATE zc_legacy_passwords SET
    updated = 1 WHERE email = ”.pSQL($email).”’);

    ignore this :

    $result = Db::getInstance()->getRow(‘ SELECT * FROM '._DB_PREFIX_
    .'customer
    WHERE active = 1 AND email = ”.pSQL($email).” AND
    deleted = 0 AND is_guest = 0′);

    so, the code will look like :

    if (!$result) {

    Db::getInstance()->Execute(‘ UPDATE '._DB_PREFIX_ .'customer SET

    passwd = ”.md5(pSQL(_COOKIE_KEY_.$passwd)).” WHERE email =

    ”.pSQL($email).”’);

    }

    Login or Signup to reply.
  2. It is so hard, even impossible to migrate password with different encryption. So, maybe too late for your question, i think anyone wanna migrate passwords should try an available to move them automatically. This tool doesnt require you any tech skills without some simple clicks. LitExtension is one of my suggestions. Of course you have to pay a little, but its not too much.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search