简体   繁体   中英

SQL Update of MD5 Passwords

I am new to PHP & SQL. I am trying to update a password from my database and I cant figure out the SQL statement so I done some research and came across this SQL statement:

UPDATE `Users` SET password= passwordmd5 (password)

I then added a bit more to the code as follows:

UPDATE `Users` SET password= tony123 MD5 (password) WHERE user_id = 55

I get the following error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'MD5 (password) WHERE user_id = 55' at line 1

What do I do?

Correct syntax would be this:

UPDATE Users
SET password = MD5('tony123')
WHERE user_id = 55;

Or, if you were storing password in plain text and you want to convert them to hashes, do this:

UPDATE Users
SET password = MD5(password);

this will work after you add db connection strings to your php file:

<?php
$password = 'tony123';
$passwordmd5 = md5($password);
$q = mysql_query("UPDATE `Users` SET password = '$passwordmd5' WHERE user_id = 55");
?>

php/mysql connection ref: http://php.net/manual/en/function.mysql-connect.php

i have stored password as a text into db and when i converted it to MD5 password i used this query,

UPDATE tablename SET columname = MD5(columname);

in above query you can also use any method instead of MD5 by just replacing MD5.

Another approach:

UPDATE Users
SET password = PASSWORD('tony123')
WHERE user_id = 55;

more info

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM