Thank The Cheese
Registered
Hello!
I am a huge PHP/MySQL n00b, so this is probably a simple thing, but I can't figure it out.
I created this script to change user passwords (which I am very proud of
)
It works great:
However I have since learnd that you can encrypt passwords that are sent to MySQL using the PASSWORD('password) syntax. This is a pretty important thing to do, so I tried to implement that by changing the queries above to:
$query="
SELECT user_id
FROM users
WHERE (username = '$username' AND password=PASSWORD('$password'))
";
and
$query="
UPDATE users
SET password = PASSWORD('$newpassword')
WHERE user_id = $row[0]
";
but this stops it from working (always returns "does not match our records"). Can't figure it out. I thought maybe it only works if the password it's changing is already encrypted, so I encrypted a few passwords and trie changing those but the same thing happens.
Am I doing something wrong?
cheers!
I am a huge PHP/MySQL n00b, so this is probably a simple thing, but I can't figure it out.
I created this script to change user passwords (which I am very proud of

It works great:
Code:
...
[COLOR="Red"]
$query="
SELECT user_id
FROM users
WHERE (username = '$username' AND password='$password')
";
[/COLOR]
$result = @mysql_query($query);
$num = mysql_num_rows($result);
if($num == 1)
{
$row = mysql_fetch_array($result, MYSQL_NUM);
[COLOR="Red"]
$query="
UPDATE users
SET password = '$newpassword'
WHERE user_id = $row[0]
";
[/COLOR]
$result = @mysql_query($query);
if(mysql_affected_rows() == 1)
{
echo '<p>Password changed.</p>';
exit();
}else{
$message = '<p>An error occured:'.mysql_error().'</p>';
}
}else{
$message = '<p>Your usename and/or password do not match our records</p>';
}
mysql_close();
...
However I have since learnd that you can encrypt passwords that are sent to MySQL using the PASSWORD('password) syntax. This is a pretty important thing to do, so I tried to implement that by changing the queries above to:
$query="
SELECT user_id
FROM users
WHERE (username = '$username' AND password=PASSWORD('$password'))
";
and
$query="
UPDATE users
SET password = PASSWORD('$newpassword')
WHERE user_id = $row[0]
";
but this stops it from working (always returns "does not match our records"). Can't figure it out. I thought maybe it only works if the password it's changing is already encrypted, so I encrypted a few passwords and trie changing those but the same thing happens.
Am I doing something wrong?
cheers!
