PrestaShop Forum

The best place in the world to ask questions about PrestaShop and get advice from our passionate community!

PrestaShop Forum

Jump to content

Password encryption. pSQL function.

7 replies to this topic
#1
gonafr

    PrestaShop Newbie

  • Members
  • Pip
  • 7 posts
Hi there,

I am trying to do some integration with another CMS and i need to find the encryption method of Prestashop.
I digg into it’s code and got into this piece of code:

/**
* Encrypt password
*
* @param object $object Object to display
*/
static public function encrypt($passwd)
{
return md5(pSQL(_COOKIE_KEY_.$passwd));
}


What is pSQL function? Where it is defined?
How can i encode one password in PHP with the same method as Prestashop?

#2
gonafr

    PrestaShop Newbie

  • Members
  • Pip
  • 7 posts
Ok i found it. Sorry for asking. It is on Db.php file under classes folder.


/**
* Sanitize data which will be injected into SQL query
*
* @param string $string SQL data which will be injected into SQL query
* @param boolean $htmlOK Does data contain HTML code ? (optional)
* @return string Sanitized data
*/
function pSQL($string, $htmlOK = false)
{
if (_PS_MAGIC_QUOTES_GPC_)
$string = stripslashes($string);
if (!is_numeric($string))
{
$string = _PS_MYSQL_REAL_ESCAPE_STRING_ ? mysql_real_escape_string($string) : addslashes($string);
if (!$htmlOK)
$string = strip_tags(nl2br2($string));
}

return $string;
}


#3
slejvak

    PrestaShop Newbie

  • Members
  • Pip
  • 3 posts
Hello,
can I have one question? Did you solve jointing Presta with other CMS? I have the same problem.

#4
gonafr

    PrestaShop Newbie

  • Members
  • Pip
  • 7 posts
Yes.

I needed to know the encryption method in Prestashop so the other CMS (Wordpress) could access the customers database table of Prestashop and do the Login with the Prestashop users.

Don't know if it's that what you want.

#5
slejvak

    PrestaShop Newbie

  • Members
  • Pip
  • 3 posts
Yes, it's in full the same, just the other CMS is not Wordpress, but it doesn't matter, i think the principle is similar.
I need to change users table in CMS for Presta's ps_customer table. Could you describe me your working in short?

#6
gonafr

    PrestaShop Newbie

  • Members
  • Pip
  • 7 posts
Well, i can give you the code i use for getting the encryption function in the other CMS (Wordpress).
I used this function's in a Wordpress plugin so i can get the login working in Wordpress.

Hope it help you.



<?php

define('_PS_MYSQL_REAL_ESCAPE_STRING_', function_exists('mysql_real_escape_string'));
define('_PS_MAGIC_QUOTES_GPC_', get_magic_quotes_gpc());

/**
* Convert \n to
* @param string $string String to transform
* @return string New string
*/
function nl2br2($string)
{
return str_replace(array("\r\n", "\r", "\n"), ' ', $string);
}


/* Sanitize data which will be injected into SQL query
*
* @param string $string SQL data which will be injected into SQL query
* @param boolean $htmlOK Does data contain HTML code ? (optional)
* @return string Sanitized data
*/
function pSQL($string, $htmlOK = false)
{
if (_PS_MAGIC_QUOTES_GPC_)
$string = stripslashes($string);
if (!is_numeric($string))
{
$string = _PS_MYSQL_REAL_ESCAPE_STRING_ ? mysql_real_escape_string($string) : addslashes($string);
if (!$htmlOK)
$string = strip_tags(nl2br2($string));
}

echo "->".$string." ";
return $string;
}

/**
* Encrypt password
*
* @param object $object Object to display
*/
function encrypt($passwd)
{
return md5(pSQL($passwd));
}

/*Ngk2AO1iQSjZDC9MbUpEYmn0Za13swCcJHO7Bek3UL0MrjKZFizE9Rxy -> Defined in /config/settings.inc.php _COOKIE_KEY_ constant*/

echo encrypt("Ngk2AO1iQSjZDC9MbUpEYmn0Za13swCcJHO7Bek3UL0MrjKZFizE9Rxy"."abcdefg");

?>



#7
slejvak

    PrestaShop Newbie

  • Members
  • Pip
  • 3 posts
Great!! Thank you very much! I'll do it today and tomorrow, then i'll send you my outcome :-)

#8
motta

    PrestaShop Newbie

  • Members
  • Pip
  • 2 posts

From 1270707869:

Yes.

I needed to know the encryption method in Prestashop so the other CMS (Wordpress) could access the customers database table of Prestashop and do the Login with the Prestashop users.

Don't know if it's that what you want.


Which WP Plugin login did u edit? The Sidebar login?
Thanks