开发者

MD5 Encrypt all the password in a table

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 Passwo开发者_Go百科rds 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


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.


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."'");
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜