简体   繁体   中英

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.

I use this to re-create the users on the new site, I would use their passwords, how can I put them there?

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?

$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));

[Passwrd_Hash] => 6ca46cdc372243d3e768c306c07edcc0:e4OKoYvFzKQVGgZRQJIFp9ntAMMQCmYf

Magento stores only hash of the customer passwords. 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 .

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

However, don't forget that Magento uses md5 to create the hash. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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