Jump to content

Edit History

UniArt

UniArt

On 5/29/2018 at 1:49 PM, Mahdi Shad said:

Hi

You should override prestashop to solve this problem:

if ( wrongPassWord ) {

    checkOldWay => setNewPassword

}

We did this for some of our clients after migration on store-migrations

Hi, it's a good solution.
I have had the same problem and I have solved changing directly the submit function of CustomerLoginForm.php in classes/form. (I don't know why override doesn't work)

This is the code that I have used, I leave it here for those who need it.

use PrestaShop\PrestaShop\Adapter\ServiceLocator;  /* put this at the beginning of the file */

/*then look for the function submit and replace it completely with this*/
 

    public function submit()
    {        
        if ($this->validate()) {
            Hook::exec('actionAuthenticationBefore');
           $oldkey = "xxxxxxxxxxxxxxxxxx_your old _COOKIE_KEY_xxxxxxxxxxxxxxxxxxxxxx";
            $pass_old_type = md5($oldkey . $this->getValue('password'));
            
        try {
            /** @var \PrestaShop\PrestaShop\Core\Crypto\Hashing $crypto */
            $crypto = ServiceLocator::get('\\PrestaShop\\PrestaShop\\Core\\Crypto\\Hashing');
            } catch (CoreException $e) {
                return false;
                }
                $customer = new Customer();
                $my_customer_values = $customer->getByEmail($this->getValue('email'));
                $passwordHash = $my_customer_values->passwd;
                        
            if ($pass_old_type === $passwordHash) {
                
                 $customer->passwd = $crypto->hash($this->getValue('password'), _COOKIE_KEY_);
                 $ok =  Db::getInstance()->update('customer', array( 'passwd' => $customer->passwd), '`id_customer` = '.(int)$customer->id);
            }
            
            $customer = new Customer();
            $authentication = $customer->getByEmail(
               $this->getValue('email'),
               $this->getValue('password')
            );
                    
            if (isset($authentication->active) && !$authentication->active) {
                $this->errors[''][] = $this->translator->trans('Your account isn\'t available at this time, please contact us', [], 'Shop.Notifications.Error');
            } elseif (!$authentication || !$customer->id || $customer->is_guest) {
                $this->errors[''][] = $this->translator->trans('Authentication failed.', [], 'Shop.Notifications.Error');
            } else {
                $this->context->updateCustomer($customer);

                Hook::exec('actionAuthentication', ['customer' => $this->context->customer]);

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

        return !$this->hasErrors();
    }

/* end of code */

This code validates the password of the client who wants to login and if it is old it becomes new and records it in the bd.

(forgive my english)

Regards

UniArt

UniArt

On 5/29/2018 at 1:49 PM, Mahdi Shad said:

Hi

You should override prestashop to solve this problem:

if ( wrongPassWord ) {

    checkOldWay => setNewPassword

}

We did this for some of our clients after migration on store-migrations

Hi, it's a good solution.
I have had the same problem and I have solved changing directly the submit function of CustomerLoginForm.php in classes/form. (I don't know why override doesn't work)

This is the code that I have used, I leave it here for those who need it.

use PrestaShop\PrestaShop\Adapter\ServiceLocator;  /* put this at the beginning of the file */

/*then look for the function submit and replace it completely with this*/
    public function submit()
    {        
        if ($this->validate()) {
            Hook::exec('actionAuthenticationBefore');
            $oldkey = "xxxxxxxxxxxxxxxxxx_your old _COOKIE_KEY_xxxxxxxxxxxxxxxxxxxxxx";  /* change this for your old key */
            $pass_old_type = md5($oldkey . $this->getValue('password'));
            
        try {
            /** @var \PrestaShop\PrestaShop\Core\Crypto\Hashing $crypto */
            $crypto = ServiceLocator::get('\\PrestaShop\\PrestaShop\\Core\\Crypto\\Hashing');
            } catch (CoreException $e) {
                return false;
                }
                $customer = new Customer();
                $my_customer_values = $customer->getByEmail($this->getValue('email'));
                $passwordHash = $my_customer_values->passwd;
                        
            if ($pass_old_type === $passwordHash) {
                
                 $customer->passwd = $crypto->hash($my_customer_pass, _COOKIE_KEY_);
                 $ok =  Db::getInstance()->update('customer', array( 'passwd' => $customer->passwd), '`id_customer` = '.(int)$customer->id);
            }
            
            $customer = new Customer();
            $authentication = $customer->getByEmail(
               $this->getValue('email'),
               $this->getValue('password')
            );
                    
            if (isset($authentication->active) && !$authentication->active) {
                $this->errors[''][] = $this->translator->trans('Your account isn\'t available at this time, please contact us', [], 'Shop.Notifications.Error');
            } elseif (!$authentication || !$customer->id || $customer->is_guest) {
                $this->errors[''][] = $this->translator->trans('Authentication failed.', [], 'Shop.Notifications.Error');
            } else {
                $this->context->updateCustomer($customer);

                Hook::exec('actionAuthentication', ['customer' => $this->context->customer]);

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

        return !$this->hasErrors();
    }

/* end of code */

This code validates the password of the client who wants to login and if it is old it becomes new and records it in the bd.

(forgive my english)

Regards

×
×
  • Create New...