首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >预存储1.7客户密码加密?

预存储1.7客户密码加密?
EN

Stack Overflow用户
提问于 2019-04-28 23:13:58
回答 1查看 3.8K关注 0票数 1

我为Prestashop 1.6制作了一些基于php的第三方系统。它可以直接连接Prestashop数据库。并且知道我把我的Presta升级到1.7.5.1,它就能工作了。只有它不再登录客户,因为我可以看到密码加密是改变。我在1.6中使用了md5(COOKIE_KEY.'password'),但我在1.7上看到的密码与md5完全不同。你能告诉我加密是怎样的吗。(如果您用php代码告诉我,情况会好得多)

Prestashop 1.7.5.1

$2y$10$6b460aRLklgWblz75NAMteYXLJwjfV6a/uN8GJKgJgPDBuNhHs.ym

123456

EN

回答 1

Stack Overflow用户

发布于 2019-04-29 00:43:10

PrestaShop 1.7.x现在使用 bcrypt 作为首选哈希方法(md5仍然支持)。

为了更好地理解用于检查密码的PrestaShop v1.6.x与1.7.x之间的行为,让我们看看Customer类中的getByEmail()方法:

代码语言:javascript
复制
/**
  * 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,则使用以下方法检索密码的加密版本:

代码语言:javascript
复制
$this->passwd = $crypto->hash($plaintextPassword);

可以通过执行以下操作来实例化散列类:

代码语言:javascript
复制
$crypto = ServiceLocator::get('\\PrestaShop\\PrestaShop\\Core\\Crypto\\Hashing');

使用 1.7类/方法的示例的PrestaShop解决方案:

代码语言:javascript
复制
<?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文件/方法:

代码语言:javascript
复制
<?php

$plaintextPassword = '123456';
$encryptedPassword = password_hash($plaintextPassword, PASSWORD_BCRYPT);
echo var_dump(password_verify($plaintextPassword, $encryptedPassword)); // True if encryption is matching

我希望这能帮到你。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55895336

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档