MD5加密表中所有密码

发布于 2024-12-04 12:06:20 字数 482 浏览 1 评论 0原文

我有一个名为 user 的数据库表,其中有一些列。其中一列是用户密码。

该密码未加密,我现在要做的就是自动获取该表中的所有用户和所有密码,对其进行加密,并使用新的加密密码更新表。

我能做些什么?使用 PHP 循环?或者什么?

我在这里有点迷失..

你能提供一个有效的例子吗?

所以我从表中选择密码

$query="SELECT * FROM users";
$ar=mysql_query($query) or die("Error selecting accounts: ".mysql_error());
$ac = mysql_num_rows($ar);
while($arow = mysql_fetch_array($ar)) {
$password = $arow['Password'];
}
AND.......

之后我完全迷失了。

你能帮我吗?

谢谢

I have a database table called user where I have some columns. One of these columns is the user password.

This password is not encrypted, what I have to do now is grab automatically all the users and all the passwords in that table, encrypt them, and update the table with the new encrypted passwords.

What can I do? Using a PHP loop? Or what?

I am a little bit lost here..

Could you please provide a working example?

So I select the Passwords from the Table

$query="SELECT * FROM users";
$ar=mysql_query($query) or die("Error selecting accounts: ".mysql_error());
$ac = mysql_num_rows($ar);
while($arow = mysql_fetch_array($ar)) {
$password = $arow['Password'];
}
AND.......

After that I am totally lost.

Could you help me?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初心未许 2024-12-11 12:06:20

输入此代码到phpMyAdmin SQL查询页面。首先登录phpMyAdmin,然后选择DB和表,然后点击“SQL”。然后您需要在字段中输入此内容并提交:

UPDATE users SET password = MD5(CONCAT(password, user_id))

编辑

OP 想要实际的 PHP 代码:

$query = "UPDATE users SET password = MD5(CONCAT(password, user_id))";
$ok = mysql_query($query);

没有比这更清晰的了。您必须确保密码字段足够大以存储 md5 哈希值。请记住,md5 哈希值的长度为 32 个字符。

Enter this code to phpMyAdmin SQL query page. First login in phpMyAdmin, then select DB and table and then click "SQL". Then you need to enter this in the field and submit:

UPDATE users SET password = MD5(CONCAT(password, user_id))

EDIT

The OP wanted actual PHP code:

$query = "UPDATE users SET password = MD5(CONCAT(password, user_id))";
$ok = mysql_query($query);

Can't get any clearer than this. You'd have to make sure that the password field is big enough to store md5 hashes. Remember that md5 hashes are 32 characters long.

可是我不能没有你 2024-12-11 12:06:20

DiegoP 询问如何使用 PHP 执行此操作,它来了(由于某种原因我无法在那里添加评论..)

$db    = Do database connection here;
$query = "UPDATE users SET password = MD5(CONCAT(password, user_id))";
$doit  = mysql_query($query, $db);

编辑:如果想循环它使用

<?php
$q = "SELECT * FROM users";
$s = mysql_query($q, $connection);

for ($i = 0; $i < mysql_num_rows($s); $i++) {
$uid = mysql_result($s, $i, "user_id");
$pass = mysql_result($s, $i, "password");
$s2 = mysql_query("UPDATE users SET password = MD5(CONCAT('".$pass."', '".$uid."')) WHERE user_id = '".$uid."'");
}
?>

DiegoP asked way to do this with PHP, and here it comes (for some reason I could not add comment there..)

$db    = Do database connection here;
$query = "UPDATE users SET password = MD5(CONCAT(password, user_id))";
$doit  = mysql_query($query, $db);

EDIT: If want to loop it use

<?php
$q = "SELECT * FROM users";
$s = mysql_query($q, $connection);

for ($i = 0; $i < mysql_num_rows($s); $i++) {
$uid = mysql_result($s, $i, "user_id");
$pass = mysql_result($s, $i, "password");
$s2 = mysql_query("UPDATE users SET password = MD5(CONCAT('".$pass."', '".$uid."')) WHERE user_id = '".$uid."'");
}
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文