Click here to Skip to main content
15,884,983 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
i want to change my password to md5 encrypted form and then save to the database please provide the code.
Posted
Comments
Sergey Alexandrovich Kryukov 8-Nov-11 22:36pm    
Any specific preference for MD5? Not safe for storing passwords!
--SA

1 solution

This is not encryption, but a cryptographic hash function, which is a very different thing. Yes, it can be good enough to store passwords. See http://en.wikipedia.org/wiki/Cryptographic_hash_function[^].

A word or warning: don't use MD5! This algorithm is considered broken, see http://en.wikipedia.org/wiki/MD5[^]. I would recommend to use the functions of the Secure Hash Algorithm ("SHA") family, see http://en.wikipedia.org/wiki/SHA2[^].

To use the cryptographic hash functions with PHP, see:
http://php.net/manual/en/function.hash.php[^].

—SA
 
Share this answer
 
Comments
sanjiv shah 8-Nov-11 23:05pm    
i have change my password field to md5 hash form in db, now i want to check the password with the password field of database.
i have taken the data from database
$result=mysql_query("SELECT * FROM `tbl_user` WHERE `user_name` = '$_POST[user_name]'");
$row = mysql_fetch_array($result);
if($row["password"]==$_POST["password"])// how to match in the password in this code
if(md5($row["password"])==$_POST["password"])//it did not work
Sergey Alexandrovich Kryukov 8-Nov-11 23:33pm    
Why did you ignore my recommendation?
--SA
markkuk 10-Nov-11 17:57pm    
Your code is a gaping security hole, not just because the use of vulnerable MD5 algorithm. The completely open possiblilty for SQL injection is even worse error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900