简体   繁体   English

如何获取用户密码并将其插入新银行

[英]How to get the user's password and insert it into a new bank

I have the hash passwords of my magento clients, I am migrating to a new bank all the data of the old bank, I would like to know how to enter the passwords in the users. 我有我的magento客户的哈希密码,我要将旧银行的所有数据迁移到新银行,我想知道如何在用户中输入密码。

I use this to re-create the users on the new site, I would use their passwords, how can I put them there? 我使用它在新站点上重新创建用户,我将使用他们的密码,如何将他们放在那里?

Code

ini_set("display_errors", 1);
require_once('app/Mage.php');
Mage::app(0);

$link = mysqli_connect('databaseip', 'login', 'password', 'database');
$link->set_charset("utf8");
$query = "SELECT * from customers";
$select = mysqli_query($link, $query);
foreach($select as $key => $selects) {
    while($row = mysqli_fetch_array($select)) {
        $teste = array(
            $clientes_id = $row['clientes_id'],
            $nome = $row['nome'],
            $sobrenome = $row['sobrenome'],
            $site = $row['site'],
            $loja = $row['loja'],
            $grupo = $row['grupo'],
            $email = $row['email'],
            $criadoem = $row['criadoem']
        );

        $customer = Mage::getModel("customer/customer");
        $customer->setId($clientes_id)->setFirstname($nome)->setLastname($sobrenome)->setWebsiteId($site)->setStoreId($loja)->setGroupId($grupo)->setEmail($email)->setCreatedAt($criadoem)->setPassword('');


        $customer->save();
    }
}

And I use this code to get the passwords, what should I do to insert them correctly in the users? 而且我使用此代码来获取密码,我该怎么做才能将其正确插入用户中?

Code

$customer_email = 'test@test.com';
$customer_password = Mage::getModel("customer/customer")->setWebsiteId(Mage::app()
->getWebsite()->getId())->loadByEmail($customer_email)->getPasswordHash()."\n";

print_r(array("Passwrd_Hash"=>$customer_password));

What I get 我得到什么

[Passwrd_Hash] => 6ca46cdc372243d3e768c306c07edcc0:e4OKoYvFzKQVGgZRQJIFp9ntAMMQCmYf

Magento stores only hash of the customer passwords. Magento仅存储客户密码的哈希。 Storing the passwords in plain text is not secure. 用纯文本存储密码是不安全的。 If you want to set the password to customer model and you don't know plain password, but you know only hash then you can use method setPasswordHash . 如果要将密码设置为客户模型,并且不知道普通密码,但只知道哈希,则可以使用setPasswordHash方法。

$customer = Mage::getModel('customer/customer')->load($id);
$customer->setPasswordHash('...');
$customer->save();

However, don't forget that Magento uses md5 to create the hash. 但是,不要忘记Magento使用md5创建哈希。 If you stored the passwords that are hashed by another way then your users would not be able to login by their passwords. 如果您存储用另一种方式哈希的密码,则您的用户将无法使用其密码登录。

If you migrate the passwords from another Magento then I guess there will no problem. 如果您从另一个Magento迁移密码,那么我想那不会有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM