我有一个opencart网页,我需要从excel中导入约5000个新用户。问题是opencart将用户密码存储为加密,但在我的Excel文件中,它们是作为文本。opencart从excel导入用户
请任何帮助。
我有一个opencart网页,我需要从excel中导入约5000个新用户。问题是opencart将用户密码存储为加密,但在我的Excel文件中,它们是作为文本。opencart从excel导入用户
请任何帮助。
好吧,几个小时后我解决了这个问题。 我分享方法,像我这样的beginers;)
打开新的文本文件,把下面的代码,然后保存为encryp.php并从您的浏览器中打开...
<?php
define("DB_SERVER", "localhost");
define("DB_USER", "your db user name"); //root for loacaldb
define("DB_PASS", "your db user pass"); //leave empty for local db
define("DB_NAME","your db name");
define("TBL_USERS", "table name");
define("FLD_USER", "email");
define("FLD_PASS", "password");
set_magic_quotes_runtime(0);
$connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME, $connection) or die(mysql_error());
$q = "SELECT ".FLD_PASS.",".FLD_USER." FROM ".TBL_USERS."";
$result = mysql_query($q, $connection);
$total=0;
$enc=0;
$doencrypt=false;
if(@$_REQUEST["do"]=="encrypt")
$doencrypt=true;
while($data = mysql_fetch_array($result))
{
if($doencrypt)
{
$total++;
if(!encrypted($data[0]))
{
$q="UPDATE ".TBL_USERS." SET ".FLD_PASS."='".md5($data[0])."' where ".FLD_USER."='".
str_replace("'","''",$data[1])."'";
mysql_query($q, $connection);
}
$enc++;
}
else
{
$total++;
if(encrypted($data[0]))
$enc++;
}
} function encrypted($str)
{
if(strlen($str)!=32)
return false;
for($i=0;$i<32;$i++)
if((ord($str[$i])<ord('0') || ord($str[$i])>ord('9')) && (ord($str[$i])<ord('a')
|| ord($str[$i])>ord('f')))
return false;
return true;
}
?>
<html>
<head><title>Encrypt passwords</title></head>
<body>
Total passwords in the table - <?php echo $total; ?><br>
<?php if($enc==$total && $total>0) { ?>
All passwords are encrypted.
<?php } else if($total>0) { ?>
Unencrypted - <?php echo $total-$enc; ?><br><br>
Click "GO" to encrypt <?php echo $total-$enc; ?> passwords.<br>
WARNING! There will be no way to decipher the passwords.<br>
<input type=button value="GO" onclick="window.location='encrypt.php?do=encrypt';">
<?php } ?>
</body>
</html>
之前插入修改密码如下:
$user_password = 'password'; // replace with the user password
$salt = substr(md5(uniqid(rand(), true)), 0, 9);
$password = sha1($salt . sha1($salt . sha1($user_password)));
插入此$password
到数据库表中的用户密码以及在盐场插入$salt
。
祝您有美好的一天!
是的,这是正确的做法,虽然OpenCart的密码哈希是通过默默无闻的安全* * :-) * *不管怎样,不要忘记在数据库中同时插入'$ salt'和'$ password'!**否则即使使用正确的密码,也不会有人能够登录。如果您对此一无所知,您也可以使用'catalog/model/account/customer.php :: addCustomer()'方法为您完成工作,但您必须首先确保给定的数组包含在这个模型的方法中使用的确切索引。 – shadyyx
@shadyyx非常感谢。我忘了提及插入'salt'字段。 –
首先,我非常高兴为您提供帮助。但我是新的PHP我不明白这个代码。我使用他们的密码从excel上传了我的用户表,但我需要加密它们。有大约5000个用户。我应该怎么做 – mbultraslan
看到的是https:/ /github.com/opencart/opencart/blob/master/upload/system/library/user.php#L37 –