【问题标题】:Import Laravel user passwords to Magento passwords将 Laravel 用户密码导入 Magento 密码
【发布时间】:2016-09-14 18:16:26
【问题描述】:

我正在将一个电子商务应用从 Laravel 迁移到 Magento。 Laravel 应用使用 Laravel 的默认密码散列,据我了解使用 Bcrypt。

Magento 客户导入让您导入密码哈希,但我认为 Magento 使用 MD5。当然,当用户尝试登录时,Magento 会将 MD5 哈希值与 Bcrypt 哈希值进行比较。

有人知道解决这个问题的方法吗?是否可以将 Magento 设置为使用与 Laravel 相同的 Bcrypt 散列?或者以其他方式将 Laravel 哈希“转换”为 Magento 可以理解的东西?

非常感谢

【问题讨论】:

  • 你当然不能“转换”哈希值;而且我不知道任何允许它与 password_hash()/password_verify() 一起使用的 Magento 插件

标签: php laravel magento hash


【解决方案1】:

扩展客户模型“Mage_Customer_Model_Customer”并写下如下内容:

class Namespace_Modulename_Model_Customer_Customer extends Mage_Customer_Model_Customer
{
    public function authenticate($login, $password)
    {
        $this->loadByEmail($login);
        if ($this->getConfirmation() && $this->isConfirmationRequired()) {
            throw Mage::exception('Mage_Core', Mage::helper('customer')->__('This account is not confirmed.'),
                self::EXCEPTION_EMAIL_NOT_CONFIRMED
            );
        }
        if (!$this->validatePassword($password)) {
            $hash=$this->getPasswordHash();
            if(!$this->YourCustomFunctionForPasswordCheck($password,$hash))
            {
                throw Mage::exception('Mage_Core', Mage::helper('customer')->__('Invalid login or password.'),
                    self::EXCEPTION_INVALID_EMAIL_OR_PASSWORD
                );
            }
        }

        Mage::dispatchEvent('customer_customer_authenticated', array(
           'model'    => $this,
           'password' => $password,
        ));

        return true;
    }
    public function YourCustomFunctionForPasswordCheck($password, $hash)
    {
        //Custom code for password check like Laravel.
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-04
    相关资源
    最近更新 更多