I have a database full of users who I generated passwords for using the code:
UPDATE users SET password = SUBSTRING(MD5(RAND()) FROM 1 FOR 8)
I made another table with just the users email / passwords for quick reference
I now want to encrypt the passwords on the main user table. I attempted this with the following code but it doesn't work. What's wrong with it?
$query = "SELECT * FROM usersreference";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$password = $row['password'];
$email = $row['email'];
$encrypted_password = md5($password);
}
$query = 'UPDATE users SET password = "' . $encrypted_password . '" WHERE email = "' . $email . '"';
$result = mysql_query($query);
if (mysql_affected_rows() == 1) {
header('Location: index.php?page=Admin');
} else {
die("there was a problem");
}
mysql_close();