我为Prestashop 1.6制作了一些基于php的第三方系统。它可以直接连接Prestashop数据库。并且知道我将我的Presta升级到1.7.5.1和IT WORKS。只有它不再登录客户,因为我可以看到密码加密已更改。我使用md5(COOKIE_KEY.'password')为1.6,但我看到1.7上的密码没有像md5那样。你能告诉我加密是怎么回事吗? (如果你用php代码告诉我它会变得更好)
Prestashop 1.7.5.1
$ 2Y $ 10 $ 6b460aRLklgWblz75NAMteYXLJwjfV6a / uN8GJKgJgPDBuNhHs.ym
为123456
PrestaShop 1.7.x现在使用bcrypt作为首选哈希方法(尽管仍然支持md5)。
为了更好地理解PrestaShop v1.6.x与1.7.x之间检查密码的行为,让我们看一下Customer类中的getByEmail()
方法:
/**
* Return customer instance from its e-mail (optionally check password).
*
* @param string $email e-mail
* @param string $plaintextPassword Password is also checked if specified
* @param bool $ignoreGuest
*
* @return bool|Customer|CustomerCore Customer instance
*/
public function getByEmail($email, $plaintextPassword = null, $ignoreGuest = true)
如果提供$plaintextPassword
,则使用以下命令检索密码的加密版本:
$this->passwd = $crypto->hash($plaintextPassword);
可以通过执行以下操作来实例化Hashing类:
$crypto = ServiceLocator::get('\\PrestaShop\\PrestaShop\\Core\\Crypto\\Hashing');
使用PrestaShop 1.7类/方法的示例解决方案:
<?php
namespace PrestaShop\PrestaShop\Core\Crypto;
include('config/config.inc.php');
$plaintextPassword = '123456';
$crypto = new Hashing;
$encryptedPassword = $crypto->hash($plaintextPassword, _COOKIE_KEY_);
echo 'Clear: '.$plaintextPassword.'<br />Encrypted: '.$encryptedPassword;
/* Result (example)
Clear: 123456
Encrypted: $2y$10$6b460aRLklgWblz75NAMteYXLJwjfV6a/uN8GJKgJgPDBuNhHs.ym */
替代解决方案,无需包含任何PrestaShop文件/方法:
<?php
$plaintextPassword = '123456';
$encryptedPassword = password_hash($plaintextPassword, PASSWORD_BCRYPT);
echo var_dump(password_verify($plaintextPassword, $encryptedPassword)); // True if encryption is matching
我希望这有帮助。