Jump to content

Moving customers passwords to new site 1.4.9->1.5.3.1


Recommended Posts

Hello, I was trying to upgrade my 1.4.9 to 1.5 and it failed. I tried all kinds of stuff but I never got it to work. I then created a new site and migrated all the data using a payed service. All is well except for the customers passwords. The recomendation is for the customer to have to create a new password using the link. This is not something I want my customers to go through and if it was me I might have cancelled my order if I couldnt log in.

 

So I'm trying to move the salt and hashes and all that stuff from my old installation. Just moving COOKIE_KEY and COOKIE_IV doesnt help and then I cant login to the admin site either. The 1.5.3.1 database as a salt table that is empty, maybe I can copy the salt info from the 1.4.9 installation somewhere? I tried the COOKIE_KEY and COOKIE_IV but that didnt work. I also tried the secure key table in 1.4.9 database but I wasnt even able to paste it in there, I guess it was too long.

 

Any ideas?

Link to comment
Share on other sites

Edit file ../config/settings.inc.php , and add :

define('_COOKIE_KEY_OLD_', 'YOUR_PS_V.1.4.9_COOKIE_KEY_');

 

Edit file ../override/classes/Customer.php, and add :

	public function getByEmail_old($email, $passwd = null, $ignore_guest = true)
{
	if (!Validate::isEmail($email) || ($passwd && !Validate::isPasswd($passwd)))
		die (Tools::displayError());

	$sql = 'SELECT *
			FROM `'._DB_PREFIX_.'customer`
			WHERE `email` = \''.pSQL($email).'\'
				'.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).'
				'.(isset($passwd) ? 'AND `passwd` = \''.Tools::encrypt_old($passwd).'\'' : '').'
				AND `deleted` = 0'.
				($ignore_guest ? ' AND `is_guest` = 0' : '');

	$result = Db::getInstance()->getRow($sql);

	if (!$result)
		return false;
	$this->id = $result['id_customer'];
	foreach ($result as $key => $value)
		if (key_exists($key, $this))
			$this->{$key} = $value;

	return $this;
}

 

 

Edit file ../override/classes/Tools.php, and add :

	public static function encrypt_old($passwd)
{
	return md5(_COOKIE_KEY_OLD_.$passwd);
}

 

Edit file ../override/controllers/front/AuthController.php, and add :

 

	protected function processSubmitLogin()
{
	Hook::exec('actionBeforeAuthentication');
	$passwd = trim(Tools::getValue('passwd'));
	$email = trim(Tools::getValue('email'));
	if (empty($email))
		$this->errors[] = Tools::displayError('E-mail address required');
	elseif (!Validate::isEmail($email))
		$this->errors[] = Tools::displayError('Invalid e-mail address');
	elseif (empty($passwd))
		$this->errors[] = Tools::displayError('Password is required');
	elseif (!Validate::isPasswd($passwd))
		$this->errors[] = Tools::displayError('Invalid password');
	else
	{
		$customer = new Customer();
		$authentication = $customer->getByEmail(trim($email), trim($passwd));
		$authentication_old = $customer->getByEmail_old(trim($email), trim($passwd));
		if ((!$authentication AND !$authentication_old) || !$customer->id)
			$this->errors[] = Tools::displayError('Authentication failed');
		else
		{
			$this->context->cookie->id_compare = isset($this->context->cookie->id_compare) ? $this->context->cookie->id_compare: CompareProduct::getIdCompareByIdCustomer($customer->id);
			$this->context->cookie->id_customer = (int)($customer->id);
			$this->context->cookie->customer_lastname = $customer->lastname;
			$this->context->cookie->customer_firstname = $customer->firstname;
			$this->context->cookie->logged = 1;
			$customer->logged = 1;
			$this->context->cookie->is_guest = $customer->isGuest();
			$this->context->cookie->passwd = $customer->passwd;
			$this->context->cookie->email = $customer->email;

			// Add customer to the context
			$this->context->customer = $customer;

			if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->context->cookie->id_cart) || Cart::getNbProducts($this->context->cookie->id_cart) == 0))
				$this->context->cookie->id_cart = (int)Cart::lastNoneOrderedCart($this->context->customer->id);

			// Update cart address
			$this->context->cart->id = $this->context->cookie->id_cart;
			$this->context->cart->setDeliveryOption(null);
			$this->context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id));

			$this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id));
			$this->context->cart->secure_key = $customer->secure_key;
			$this->context->cart->update();
			$this->context->cart->autosetProductAddress();

			Hook::exec('actionAuthentication');

			// Login information have changed, so we check if the cart rules still apply
			CartRule::autoRemoveFromCart($this->context);
			CartRule::autoAddToCart($this->context);

			if (!$this->ajax)
			{
				if ($back = Tools::getValue('back'))
					Tools::redirect(html_entity_decode($back));
				Tools::redirect('index.php?controller=my-account');
			}
		}
	}
	if ($this->ajax)
	{
		$return = array(
			'hasError' => !empty($this->errors),
			'errors' => $this->errors,
			'token' => Tools::getToken(false)
		);
		die(Tools::jsonEncode($return));
	}
	else
		$this->context->smarty->assign('authentification_error', $this->errors);
}

 

Finally

create csv file to update XX_customer_group table database for all id_customer

set group to 3 (customer), and import to your Prestashop database

 

Done :)

AuthController.php

Customer.php

Tools.php

  • Like 2
Link to comment
Share on other sites

  • 1 month later...

Hello Gonebdg,

 

I followed everything you said above here but it seems to not work?(still getting authentication failed) Do i need to re-import all my customers after this fix? since i have done the import before the fix? All tough i did fully restore the customer group through the database.

 

About the customers it self i have done this through CSV imporrt within the back office of prestashop is this the right way or should i do this through the database?

 

Kind regards,

Lars van Oostrum

Link to comment
Share on other sites

Hi Lars,

Did you have modify your prestashop settings.inc.php file as mentioned above ?

I've uploaded 3 files above, so you don't have to edit the overriden files. Did you use it and have uploading it into the right directory ?

Did you do the last thing that has been mentioned above ?

Finally

create csv file to update XX_customer_group table database for all id_customer

set group to 3 (customer), and import to your Prestashop database

Link to comment
Share on other sites

  • 4 months later...

Hello Gonebdg,

 

I also failed with it (fresh install of 1.5.4), so let me ask very specific questions:

 

- I added the line to the settings.inc.php file

 

- In my override/classes diretory there was not those files, that you mentioned (Customer.php, Tools.php), so I just simply copied the files that you posted into that folder

 

- Same with override/controllers/front folder (I copied your AuthController.php file there too)

 

- From within phpMyAdmin (from the old, 1.4 presta install) I exported a few rows of the ps_customer table, into a .csv file

 

- In the new install, I csv imported the previous file (as Customer entity)

 

Still, the old password does not work. Where did I go wrong?

 

Thank a lot,

Istvan Derenyi

Link to comment
Share on other sites

  • 6 months later...
  • 1 month later...

I made a succesfully customers import incl. passwords(update from ps_1.3.7 to ps_1.6) with some additions to Gonebdg post:

 

I don't know why, but Prestashop Developers wants to re-encrypt the passwords from the csv file.

 

The encription is make in line 2323 from customerImport method of AdminImportController.php and the code is:

*******

            if ($customer->passwd)
                $customer->passwd = Tools::encrypt($customer->passwd);

*******

 

The solution i founded was to comment those 2 lines and let the passwords as they are extracted

from the old prestashop database in the csv file, where was added already encrypted when customers

created their accounts.

 

To do that I overrided AdminImportController.php

by adding 

overide/controllers/admin/AdminImportController.php

 

with the following code on it:

***********************************

 

<?php


class AdminImportController extends AdminImportControllerCore
{
    
    public function customerImport()
    {
        $customer_exist = false;
        $this->receiveTab();
        $handle = $this->openCsvFile();
        $default_language_id = (int)Configuration::get('PS_LANG_DEFAULT');
        $id_lang = Language::getIdByIso(Tools::getValue('iso_lang'));
        if (!Validate::isUnsignedId($id_lang))
            $id_lang = $default_language_id;
        AdminImportController::setLocale();
        for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++)
        {
            if (Tools::getValue('convert'))
                $line = $this->utf8EncodeArray($line);
            $info = AdminImportController::getMaskedRow($line);

            AdminImportController::setDefaultValues($info);

            if (Tools::getValue('forceIDs') && isset($info['id']) && (int)$info['id'])
                $customer = new Customer((int)$info['id']);
            else
            {
                if (array_key_exists('id', $info) && (int)$info['id'] && Customer::customerIdExistsStatic((int)$info['id']))
                    $customer = new Customer((int)$info['id']);
                else
                    $customer = new Customer();
            }

            if (array_key_exists('id', $info) && (int)$info['id'] && Customer::customerIdExistsStatic((int)$info['id']))
            {
                $current_id_customer = $customer->id;
                $current_id_shop = $customer->id_shop;
                $current_id_shop_group = $customer->id_shop_group;
                $customer_exist = true;
                $customer_groups = $customer->getGroups();
                $addresses = $customer->getAddresses((int)Configuration::get('PS_LANG_DEFAULT'));
            }

            // Group Importation
            if (isset($info['group']) && !empty($info['group']))
            {
                foreach (explode($this->multiple_value_separator, $info['group']) as $key => $group)
                {
                    $group = trim($group);
                    if(empty($group))
                        continue;
                    $id_group = false;
                    if (is_numeric($group) && $group)
                    {
                        $myGroup = new Group((int)$group);
                        if (Validate::isLoadedObject($myGroup))
                            $customer_groups[] = (int)$group;
                        continue;
                    }                        
                    $myGroup = Group::searchByName($group);
                    if (isset($myGroup['id_group']) && $myGroup['id_group'])
                        $id_group = (int)$myGroup['id_group'];
                    if (!$id_group)
                    {
                        $myGroup = new Group();
                        $myGroup->name = Array($id_lang => $group);
                        if ($id_lang != $default_language_id)
                            $myGroup->name = $myGroup->name + array($default_language_id => $group);
                        $myGroup->price_display_method = 1;
                        $myGroup->add();
                        if (Validate::isLoadedObject($myGroup))
                            $id_group = (int)$myGroup->id;
                    }
                    if ($id_group)
                        $customer_groups[] = (int)$id_group;
                }
            }
            elseif(empty($info['group']) && isset($customer->id) && $customer->id)
                $customer_groups = array(0 => Configuration::get('PS_CUSTOMER_GROUP'));
                
            AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $customer);

            //if ($customer->passwd)
                //$customer->passwd = Tools::encrypt($customer->passwd);

            $id_shop_list = explode($this->multiple_value_separator, $customer->id_shop);
            $customers_shop = array();
            $customers_shop['shared'] = array();
            $default_shop = new Shop((int)Configuration::get('PS_SHOP_DEFAULT'));
            if (Shop::isFeatureActive() && $id_shop_list)
            {
                foreach ($id_shop_list as $id_shop)
                {
                    if (empty($id_shop))
                        continue;
                    $shop = new Shop((int)$id_shop);
                    $group_shop = $shop->getGroup();
                    if ($group_shop->share_customer)
                    {
                        if (!in_array($group_shop->id, $customers_shop['shared']))
                            $customers_shop['shared'][(int)$id_shop] = $group_shop->id;
                    }
                    else
                        $customers_shop[(int)$id_shop] = $group_shop->id;
                }
            }
            else
            {
                $default_shop = new Shop((int)Configuration::get('PS_SHOP_DEFAULT'));
                $default_shop->getGroup();
                $customers_shop[$default_shop->id] = $default_shop->getGroup()->id;
            }

            //set temporally for validate field
            $customer->id_shop = $default_shop->id;
            $customer->id_shop_group = $default_shop->getGroup()->id;
            if (isset($info['id_default_group']) && !empty($info['id_default_group']) && !is_numeric($info['id_default_group']))
            {
                $info['id_default_group'] = trim($info['id_default_group']);
                $myGroup = Group::searchByName($info['id_default_group']);
                if (isset($myGroup['id_group']) && $myGroup['id_group'])
                    $info['id_default_group'] = (int)$myGroup['id_group'];
            }
            $myGroup = new Group($customer->id_default_group);
            if (!Validate::isLoadedObject($myGroup))
                $customer->id_default_group = (int)Configuration::get('PS_CUSTOMER_GROUP');
            $customer_groups[] = (int)$customer->id_default_group;
            $customer_groups = array_flip(array_flip($customer_groups));
            $res = true;
            if (($field_error = $customer->validateFields(UNFRIENDLY_ERROR, true)) === true &&
                ($lang_field_error = $customer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true)
            {
                foreach ($customers_shop as $id_shop => $id_group)
                {
                    if ($id_shop == 'shared')
                    {
                        foreach ($id_group as $key => $id)
                        {
                            $customer->id_shop = (int)$key;
                            $customer->id_shop_group = (int)$id;
                            if ($customer_exist && ($current_id_shop_group == $id || in_array($current_id_shop, ShopGroup::getShopsFromGroup($id))))
                            {
                                $customer->id = $current_id_customer;
                                $res &= $customer->update();
                            }
                            else
                            {
                                $res &= $customer->add();
                                if (isset($addresses))
                                    foreach ($addresses as $address)
                                    {
                                        $address['id_customer'] = $customer->id;
                                        unset($address['country'], $address['state'], $address['state_iso'], $address['id_address']    );
                                        Db::getInstance()->insert('address', $address);
                                    }
                            }
                            if ($res && isset($customer_groups))
                                $customer->updateGroup($customer_groups);
                        }
                    }
                    else
                    {
                        $customer->id_shop = $id_shop;
                        $customer->id_shop_group = $id_group;
                        if ($customer_exist && $id_shop == $current_id_shop)
                        {
                            $customer->id = $current_id_customer;
                            $res &= $customer->update();
                        }
                        else
                        {
                            $res &= $customer->add();
                            if (isset($addresses))
                                foreach ($addresses as $address)
                                {
                                    $address['id_customer'] = $customer->id;
                                    unset($address['country'], $address['state'], $address['state_iso'], $address['id_address']);
                                    Db::getInstance()->insert('address', $address);
                                }
                        }
                        if ($res && isset($customer_groups))
                            $customer->updateGroup($customer_groups);
                    }
                }
            }
            unset($customer_groups);
            $customer_exist = false;
            if (!$res)
            {
                $this->errors[] = sprintf(
                    Tools::displayError('%1$s (ID: %2$s) cannot be saved'),
                    $info['email'],
                    (isset($info['id']) && !empty($info['id']))? $info['id'] : 'null'
                );
                $this->errors[] = ($field_error !== true ? $field_error : '').(isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '').
                    Db::getInstance()->getMsgError();
            }
        }
        $this->closeCsvFile($handle);
    }    

}

 

***********************************

  • Like 1
Link to comment
Share on other sites

I tried the ktapet solution... not working!

 

I added the file override/controllers/admin/AdminImportController.php with the code mentioned, but the hashed password is still encrypted.

did you delete the /cache/class_index.php file after you add override/controllers/admin/AdminImportController.php

 file?

Edited by ktapet (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

Edit file ../config/settings.inc.php , and add :

define('_COOKIE_KEY_OLD_', 'YOUR_PS_V.1.4.9_COOKIE_KEY_');
Edit file ../override/classes/Customer.php, and add :

public function getByEmail_old($email, $passwd = null, $ignore_guest = true)
	{
		if (!Validate::isEmail($email) || ($passwd && !Validate::isPasswd($passwd)))
			die (Tools::displayError());

		$sql = 'SELECT *
				FROM `'._DB_PREFIX_.'customer`
				WHERE `email` = \''.pSQL($email).'\'
					'.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).'
					'.(isset($passwd) ? 'AND `passwd` = \''.Tools::encrypt_old($passwd).'\'' : '').'
					AND `deleted` = 0'.
					($ignore_guest ? ' AND `is_guest` = 0' : '');

		$result = Db::getInstance()->getRow($sql);

		if (!$result)
			return false;
		$this->id = $result['id_customer'];
		foreach ($result as $key => $value)
			if (key_exists($key, $this))
				$this->{$key} = $value;

		return $this;
	}

Edit file ../override/classes/Tools.php, and add :

public static function encrypt_old($passwd)
	{
		return md5(_COOKIE_KEY_OLD_.$passwd);
	}
Edit file ../override/controllers/front/AuthController.php, and add :

 

protected function processSubmitLogin()
	{
		Hook::exec('actionBeforeAuthentication');
		$passwd = trim(Tools::getValue('passwd'));
		$email = trim(Tools::getValue('email'));
		if (empty($email))
			$this->errors[] = Tools::displayError('E-mail address required');
		elseif (!Validate::isEmail($email))
			$this->errors[] = Tools::displayError('Invalid e-mail address');
		elseif (empty($passwd))
			$this->errors[] = Tools::displayError('Password is required');
		elseif (!Validate::isPasswd($passwd))
			$this->errors[] = Tools::displayError('Invalid password');
		else
		{
			$customer = new Customer();
			$authentication = $customer->getByEmail(trim($email), trim($passwd));
			$authentication_old = $customer->getByEmail_old(trim($email), trim($passwd));
			if ((!$authentication AND !$authentication_old) || !$customer->id)
				$this->errors[] = Tools::displayError('Authentication failed');
			else
			{
				$this->context->cookie->id_compare = isset($this->context->cookie->id_compare) ? $this->context->cookie->id_compare: CompareProduct::getIdCompareByIdCustomer($customer->id);
				$this->context->cookie->id_customer = (int)($customer->id);
				$this->context->cookie->customer_lastname = $customer->lastname;
				$this->context->cookie->customer_firstname = $customer->firstname;
				$this->context->cookie->logged = 1;
				$customer->logged = 1;
				$this->context->cookie->is_guest = $customer->isGuest();
				$this->context->cookie->passwd = $customer->passwd;
				$this->context->cookie->email = $customer->email;
				
				// Add customer to the context
				$this->context->customer = $customer;
				
				if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->context->cookie->id_cart) || Cart::getNbProducts($this->context->cookie->id_cart) == 0))
					$this->context->cookie->id_cart = (int)Cart::lastNoneOrderedCart($this->context->customer->id);
				
				// Update cart address
				$this->context->cart->id = $this->context->cookie->id_cart;
				$this->context->cart->setDeliveryOption(null);
				$this->context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id));
				
				$this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id));
				$this->context->cart->secure_key = $customer->secure_key;
				$this->context->cart->update();
				$this->context->cart->autosetProductAddress();

				Hook::exec('actionAuthentication');

				// Login information have changed, so we check if the cart rules still apply
				CartRule::autoRemoveFromCart($this->context);
				CartRule::autoAddToCart($this->context);

				if (!$this->ajax)
				{
					if ($back = Tools::getValue('back'))
						Tools::redirect(html_entity_decode($back));
					Tools::redirect('index.php?controller=my-account');
				}
			}
		}
		if ($this->ajax)
		{
			$return = array(
				'hasError' => !empty($this->errors),
				'errors' => $this->errors,
				'token' => Tools::getToken(false)
			);
			die(Tools::jsonEncode($return));
		}
		else
			$this->context->smarty->assign('authentification_error', $this->errors);
	}
Finally

create csv file to update XX_customer_group table database for all id_customer

set group to 3 (customer), and import to your Prestashop database

 

Done :)

 

 

It worked for me! version 1.3.2 -> 1.5.6 (my new site is not online yet, but all the test I did indicate that these changes worked). Many thanks gonebdg!!

 

PS: don't forget to change "'YOUR_PS_V.1.4.9_COOKIE_KEY_'" by your cookie key located in the "old" ../config/settings.inc.php 

Also, don't forget to delete /cache/class_index.php file

Link to comment
Share on other sites

It worked for me! version 1.3.2 -> 1.5.6 (my new site is not online yet, but all the test I did indicate that these changes worked). Many thanks gonebdg!!

I tried exactly the same thing (I am running v1.6), but when I upload the Customer.php and Tools.php file I get only blank pages (both in FO and BO)...

 

PS. I did replace the old secure key and deleted the class_index.php

Link to comment
Share on other sites

edit config/defines.inc.php

 

change the following line

define('_PS_MODE_DEV_', false);

to..

define('_PS_MODE_DEV_', true);

Then try again and let us know what the error message is

 

Fatal error: Call to undefined method Tools::isPHPCLI() in ~/config/config.inc.php on line 64

Link to comment
Share on other sites

Ok, so you are past your original error then?

I probably have another error...

When I go to my account page, the page is blank, but not entirely; I can see the header, sidebar and footer.

I've set..

define('_PS_DISPLAY_COMPATIBILITY_WARNING_', false);

and

@ini_set('display_errors', 'on');

but no error is shown...

Link to comment
Share on other sites

  • 2 months later...

to 1.6

 

Edit file ../config/settings.inc.php , and add :
 

define('_COOKIE_KEY_OLD_', 'YOUR_PS_V.1.4.9_COOKIE_KEY_');

 

 

Edit file /controllers/front/Customer.php, and change :
 

public function getByEmail($email, $passwd = null, $ignore_guest = true)
    {
        if (!Validate::isEmail($email) || ($passwd && !Validate::isPasswd($passwd)))
            die (Tools::displayError());

        $sql = 'SELECT *
                FROM `'
._DB_PREFIX_.'customer`
                WHERE `email` = \''
.pSQL($email).'\'
                    '
.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).'
                    '
.(isset($passwd) ? 'AND (`passwd` = \''.Tools::encrypt($passwd).'\' OR `passwd` = \''.Tools::encrypt_old($passwd).'\')' : '').'
                    AND `deleted` = 0'
.
                    ($ignore_guest ? ' AND `is_guest` = 0' : '');

        $result = Db::getInstance()->getRow($sql);

        if (!$result)
            return false;
        $this->id = $result['id_customer'];
        foreach ($result as $key => $value)
            if (key_exists($key, $this))
                $this->{$key} = $value;

        return $this;
    }

 

Edit file /controllers/front/Tools.php, and add :

public static function encrypt_old($passwd)
    {
        return md5(_COOKIE_KEY_OLD_.$passwd);
    }

 

 

Edit file : /controllers/front/IdentityController.php and change :

 

public function postProcess()
    {
        $origin_newsletter = (bool)$this->customer->newsletter;

        if (Tools::isSubmit('submitIdentity'))
        {
            $email = trim(Tools::getValue('email'));

            if (Tools::getValue('months') != '' && Tools::getValue('days') != '' && Tools::getValue('years') != '')
                $this->customer->birthday = (int)(Tools::getValue('years')).'-'.(int)(Tools::getValue('months')).'-'.(int)(Tools::getValue('days'));
            elseif (Tools::getValue('months') == '' && Tools::getValue('days') == '' && Tools::getValue('years') == '')
                $this->customer->birthday = null;
            else
                $this->errors[] = Tools::displayError('Invalid date of birth.');

            if (Tools::getIsset('old_passwd'))
                $old_passwd = trim(Tools::getValue('old_passwd'));
            
            if (!Validate::isEmail($email))
                $this->errors[] = Tools::displayError('This email address is not valid');
            elseif ($this->customer->email != $email && Customer::customerExists($email, true))
                $this->errors[] = Tools::displayError('An account using this email address has already been registered.');
            elseif (!Tools::getIsset('old_passwd') || (Tools::encrypt($old_passwd) != $this->context->cookie->passwd && Tools::encrypt_old($old_passwd) != $this->context->cookie->passwd))
                $this->errors[] = Tools::displayError('The password you entered is incorrect.');
            elseif (Tools::getValue('passwd') != Tools::getValue('confirmation'))
                $this->errors[] = Tools::displayError('The password and confirmation do not match.');
            else
            {
                $prev_id_default_group = $this->customer->id_default_group;

                // Merge all errors of this file and of the Object Model
                $this->errors = array_merge($this->errors, $this->customer->validateController());
            }

            if (!count($this->errors))
            {
                $this->customer->id_default_group = (int)$prev_id_default_group;
                $this->customer->firstname = Tools::ucwords($this->customer->firstname);

                if (Configuration::get('PS_B2B_ENABLE'))
                {
                    $this->customer->website = Tools::getValue('website'); // force update of website, even if box is empty, this allows user to remove the website
                    $this->customer->company = Tools::getValue('company');
                }

                if (!Tools::getIsset('newsletter'))
                    $this->customer->newsletter = 0;
                elseif (!$origin_newsletter && Tools::getIsset('newsletter'))
                    if ($module_newsletter = Module::getInstanceByName('blocknewsletter'))
                        if ($module_newsletter->active)
                            $module_newsletter->confirmSubscription($this->customer->email);

                if (!Tools::getIsset('optin'))
                    $this->customer->optin = 0;
                if (Tools::getValue('passwd'))
                    $this->context->cookie->passwd = $this->customer->passwd;
                if ($this->customer->update())
                {
                    $this->context->cookie->customer_lastname = $this->customer->lastname;
                    $this->context->cookie->customer_firstname = $this->customer->firstname;
                    $this->context->smarty->assign('confirmation', 1);
                }
                else
                    $this->errors[] = Tools::displayError('The information cannot be updated.');
            }
        }
        else
            $_POST = array_map('stripslashes', $this->customer->getFields());

        return $this->customer;
    }

Link to comment
Share on other sites

  • 3 months later...

Edit file ../config/settings.inc.php , and add :

define('_COOKIE_KEY_OLD_', 'YOUR_PS_V.1.4.9_COOKIE_KEY_');
Edit file ../override/classes/Customer.php, and add :

public function getByEmail_old($email, $passwd = null, $ignore_guest = true)
	{
		if (!Validate::isEmail($email) || ($passwd && !Validate::isPasswd($passwd)))
			die (Tools::displayError());

		$sql = 'SELECT *
				FROM `'._DB_PREFIX_.'customer`
				WHERE `email` = \''.pSQL($email).'\'
					'.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).'
					'.(isset($passwd) ? 'AND `passwd` = \''.Tools::encrypt_old($passwd).'\'' : '').'
					AND `deleted` = 0'.
					($ignore_guest ? ' AND `is_guest` = 0' : '');

		$result = Db::getInstance()->getRow($sql);

		if (!$result)
			return false;
		$this->id = $result['id_customer'];
		foreach ($result as $key => $value)
			if (key_exists($key, $this))
				$this->{$key} = $value;

		return $this;
	}

Edit file ../override/classes/Tools.php, and add :

public static function encrypt_old($passwd)
	{
		return md5(_COOKIE_KEY_OLD_.$passwd);
	}
Edit file ../override/controllers/front/AuthController.php, and add :

 

protected function processSubmitLogin()
	{
		Hook::exec('actionBeforeAuthentication');
		$passwd = trim(Tools::getValue('passwd'));
		$email = trim(Tools::getValue('email'));
		if (empty($email))
			$this->errors[] = Tools::displayError('E-mail address required');
		elseif (!Validate::isEmail($email))
			$this->errors[] = Tools::displayError('Invalid e-mail address');
		elseif (empty($passwd))
			$this->errors[] = Tools::displayError('Password is required');
		elseif (!Validate::isPasswd($passwd))
			$this->errors[] = Tools::displayError('Invalid password');
		else
		{
			$customer = new Customer();
			$authentication = $customer->getByEmail(trim($email), trim($passwd));
			$authentication_old = $customer->getByEmail_old(trim($email), trim($passwd));
			if ((!$authentication AND !$authentication_old) || !$customer->id)
				$this->errors[] = Tools::displayError('Authentication failed');
			else
			{
				$this->context->cookie->id_compare = isset($this->context->cookie->id_compare) ? $this->context->cookie->id_compare: CompareProduct::getIdCompareByIdCustomer($customer->id);
				$this->context->cookie->id_customer = (int)($customer->id);
				$this->context->cookie->customer_lastname = $customer->lastname;
				$this->context->cookie->customer_firstname = $customer->firstname;
				$this->context->cookie->logged = 1;
				$customer->logged = 1;
				$this->context->cookie->is_guest = $customer->isGuest();
				$this->context->cookie->passwd = $customer->passwd;
				$this->context->cookie->email = $customer->email;
				
				// Add customer to the context
				$this->context->customer = $customer;
				
				if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->context->cookie->id_cart) || Cart::getNbProducts($this->context->cookie->id_cart) == 0))
					$this->context->cookie->id_cart = (int)Cart::lastNoneOrderedCart($this->context->customer->id);
				
				// Update cart address
				$this->context->cart->id = $this->context->cookie->id_cart;
				$this->context->cart->setDeliveryOption(null);
				$this->context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id));
				
				$this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id));
				$this->context->cart->secure_key = $customer->secure_key;
				$this->context->cart->update();
				$this->context->cart->autosetProductAddress();

				Hook::exec('actionAuthentication');

				// Login information have changed, so we check if the cart rules still apply
				CartRule::autoRemoveFromCart($this->context);
				CartRule::autoAddToCart($this->context);

				if (!$this->ajax)
				{
					if ($back = Tools::getValue('back'))
						Tools::redirect(html_entity_decode($back));
					Tools::redirect('index.php?controller=my-account');
				}
			}
		}
		if ($this->ajax)
		{
			$return = array(
				'hasError' => !empty($this->errors),
				'errors' => $this->errors,
				'token' => Tools::getToken(false)
			);
			die(Tools::jsonEncode($return));
		}
		else
			$this->context->smarty->assign('authentification_error', $this->errors);
	}
Finally

create csv file to update XX_customer_group table database for all id_customer

set group to 3 (customer), and import to your Prestashop database

 

Done :)

 

 i just followed your post. and now i cant access FO and BO on my local server. the error message is Fatal error: Class 'ToolsCore' not found in C:\wamp\www\mysite\override\classes\Tools.php on line 4.  Kindly your help.. Thank you

Link to comment
Share on other sites

Basic understanding for customer migrations from the old to new Prestashop versions is :
The customers data on your old prestashop version are using different Cookie Key.

This Cookie Key is defined as PHP Constan variable _COOKIE_KEY_
Customers password hash and secure key will be different if the _COOKIE_KEY_ is different

Modification should be working well for PS v1.1 - PS v1.5 to PS v1.6
because there is no major different in password encryption method

md5(_COOKIE_KEY_.$passwd);

Therefore you will need to modified you Prestashop, so the old _COOKIE_KEY_ is able to be used for authentication.

BUT if your new Prestashop is a clean install Prestashop and there are no customers data yet,

then it's not necessary to modify your Prestashop (override the classes and controller files).
What You have to do is :
Change the value of constan var _COOKIE_KEY_  which defined on your new Prestashop (@ config/settings.inc.php) with the old value of  _COOKIE_KEY_ on your old Prestashop version.
That's all ... :)

 

But for those who still need modifications, you can found and use the necessary files attached in here :

Customers data migration.zip

 

Instructions :

  1. Extract the compressed file to your computer directory and Upload folder /override/ (with all folder and files contained) to your Prestashop installation directory
  2. From your old Prestashop, open file config/settings.inc.php
  3. From your new Prestashop, open file config/settings.inc.php and add :
    define('_COOKIE_KEY_OLD_', '_YOUR_OLD_COOKIE_KEY_');
  4. Change _YOUR_OLD_COOKIE_KEY_ with value of _COOKIE_KEY_ from your old Prestashop
  5. Save modifications
  6. Prepare your customer and customer_group database file
  7. Depend on your old Prestashop version, You might have to adjust the corresponding value with DB column. Therefore i suggest to use Ms.Excel to create customer and customer_group database file in *.csv file format
  8. Import all customers data from your old Prestashop to new Prestashop database (DB table PREFIX_customer and PREFIX_customer_group )
  9. DONE :rolleyes:

 

Edited by gonebdg - webindoshop.com (see edit history)
Link to comment
Share on other sites

  • 5 months later...

just wondering can anyone help? im getting this error: Fatal error: Class 'ToolsCore' not found in /var/www/web/shop3/tools/profiling/Tools.php on line 28 . site is http://4u.ie/shop3 . i have renamed and renamed back to original name /classes/Tools.php and Currency.php (so no changes). V upset about this, such a small thing and has taken up nearly the day :(

Link to comment
Share on other sites

  • 7 months later...
Moving customers passwords to new site 1.2.4.0->1.6.1.1

Hello, I was trying to upgrade my 1.2.4.0 to 1.6.1.1 .

 

I created a new site and migrated all the data using a payed service. All is well except for the customers passwords. The recomendation is for the customer to have to create a new password using the link. This is not something I want my customers to go through and if it was me I might have cancelled my order if I couldnt log in. 

 

So I'm trying to move the salt and hashes and all that stuff from my old installation. Just moving COOKIE_KEY and COOKIE_IV doesnt help and then I cant login to the admin site either. 

 

How Can i do in 1.6.1.1 version.
Link to comment
Share on other sites

  • 4 weeks later...
  • 10 months later...

Hi i have a problem with Customer Password

 

I bought a module leading to migrate customer data, but they can not access the website because it does not accept the password.
 
Here two information of the installation document, but when I do what it says in the document it blocks access to the BO, can someone help me?
 
When the migration is finished:
1. Step to the root folder of your Source PrestaShop
2. Enter “ config ” folder
3. Open “ settings.inc.php ” file as a text document
4. Copy COOKIE_KEY code
After copying COOKIE_KEY code, enter the same directory but on your Target PrestaShop ( /root
folder/config/settings.inc.php ) and replace the COOKIE_KEY you see with the one you’ve
copied from Source PrestaShop .
On this point, the migration of customer passwords is completely finished. The last step would be
your admin account password recovery (required for admin accounts only).
Click on “ I forget my password ”, enter email and a new password to your admin account will be
sent to your email.
 
 
 
Link to comment
Share on other sites

I bought a module leading to migrate customer data, but they can not access the website because it does not accept the password.

 

If you purchased a module to migrate the data, then why not contact the author of the module who provided you with these non working instructions?

Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...