我刚注意到magento企业和社区两个版本都使用不同的算法来存储密码.我知道社区版使用md5.任何人都可以告诉我企业版中使用了哪种机制,如果我们想迁移到社区版,我们如何解密企业密码?
Jos*_*ano 14
我认为这是在您app/etc/local.xml
或app/etc/enterprise.xml
Magento EE上
解密功能在Magento企业版上
/**
* Decrypt a string
*
* @param string $data
* @return string
*/
public function decrypt($data)
{
return str_replace("\x0", '', trim($this->_getCrypt()->decrypt(base64_decode((string)$data))));
}
Run Code Online (Sandbox Code Playgroud)
和
/**
* Instantiate crypt model
*
* @param string $key
* @return Varien_Crypt_Mcrypt
*/
protected function _getCrypt($key = null)
{
if (!$this->_crypt) {
if (null === $key) {
$key = (string)Mage::getConfig()->getNode('global/crypt/key');
}
$this->_crypt = Varien_Crypt::factory()->init($key);
}
return $this->_crypt;
}
Run Code Online (Sandbox Code Playgroud)
它似乎与Enterprise Edition或Community Edition上的功能相同.您应该向Magento Enterprise Edition的所有者询问cript密钥并使用CE解密.这很好,因为我偷偷摸摸到Magento Enterprise Edition的代码,代码与Community Edition 相同(用于加密/解密)
评论1后添加:
/**
* Hash a string
*
* @param string $data
* @return string
*/
public function hash($data)
{
return md5($data);
}
/**
* Validate hash against hashing method (with or without salt)
*
* @param string $password
* @param string $hash
* @return bool
* @throws Exception
*/
public function validateHash($password, $hash)
{
$hashArr = explode(':', $hash);
switch (count($hashArr)) {
case 1:
return $this->hash($password) === $hash;
case 2:
return $this->hash($hashArr[1] . $password) === $hashArr[0];
}
Mage::throwException('Invalid hash.');
}
Run Code Online (Sandbox Code Playgroud)
Fia*_*abs 11
哈希是单向加密.您不应该能够解密密码.
密码的基本操作:
客户注册一个帐户并输入密码.系统添加salt,加密密码并将生成的密码哈希存储在数据库中.
客户登录后输入密码.系统添加salt,加密密码并将生成的密码哈希与存储的密码哈希进行比较.当哈希值相等时,登录系统知道客户知道密码而实际上并不知道密码本身.
因此,如果一个系统使用SHA1而另一个系统使用旧的过期MD5,则可以将密码重新输入系统的唯一方法是让客户重新输入密码,以便调用新的哈希算法并存储新的哈希.
您拥有企业源代码,编写一个使用企业散列函数来存储和比较密码的模块,并且您将使用CE和更新的安全增强方法来存储密码,并且应该能够从密码中获取密码哈希值.旧网站.
一些其他信息:
使用的加密方法可在Mage_Core_Model_Encryption类中找到.
感兴趣的三个功能是:
public function hash($data)
public function getHash($password, $salt = false)
public function validateHash($password, $hash)
功能代码来自1.7.xx
>
public function hash($data)
{
return md5($data);
}
Run Code Online (Sandbox Code Playgroud)
>
public function getHash($password, $salt = false)
{
if (is_integer($salt)) {
$salt = $this->_helper->getRandomString($salt);
}
return $salt === false ? $this->hash($password) : $this->hash($salt . $password) . ':' . $salt;
}
Run Code Online (Sandbox Code Playgroud)
>
public function validateHash($password, $hash)
{
$hashArr = explode(':', $hash);
switch (count($hashArr)) {
case 1:
return $this->hash($password) === $hash;
case 2:
return $this->hash($hashArr[1] . $password) === $hashArr[0];
}
Mage::throwException('Invalid hash.');
}
Run Code Online (Sandbox Code Playgroud)
CE和Enterprise似乎都使用相同的例程,您必须在拥有企业代码时检查它.
更改app/etc/local.xml文件中的加密密钥以匹配企业版中的密钥,然后将企业数据导入CE数据库,将允许访问加密数据.密码虽然存储为哈希(见上面的功能块),因此不可逆.local.xml中存储加密密钥的相关部分:
<crypt>
<key>< ![CDATA[-encryption-key-here-]]></key>
</crypt>
Run Code Online (Sandbox Code Playgroud)
我们还使用不同的密码算法转移到另一个系统.我们所做的确实像Fiasco建议的那样:
- >编写一个覆盖Magento_Core_Model_Encryption的自定义模块,并更改该hash
函数以匹配加密密码的算法.
在您的模块配置中:
<global>
<helpers>
<core>
<encryption_model>MyCompany_Module_Model_Encryption</encryption_model>
</core>
</helpers>
</global>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
14772 次 |
最近记录: |