How to store and retrieve password in md5 hash with PHP- MySQL ?

Posted By: KP On September 7, 2011 Under Other, Programming Categories


A website which is dealing with user registrations should always store user passwords as MD5 hash for security reasons. An easy tutorial for storing and retrieving MD5 hash in a MySQL database as follows.

Flowchart for storing a password:

md5-encrypt-flowchart

While storing password into database first convert user’s entered password using md5 function then store into database.

PHP code encrypting to MD5:

$pass=$_POST[‘password’];

$encryptedpass=md5($pass);

//SQL query to store $encryptedpass into database

Flowchart for decoding MD5 password:

md5-decrypt-flowchart

While retrieving password from database first take password from user(plain text), convert it to md5 hash and compare with stored value in database.

PHP code decrypting from MD5:

$pass=$_POST[‘password’];

$encryptedpass=md5($pass);

//SQL query to compare $encryptedpass with stored database

MD5 hash cannot be decoded directly. There is no such formula/function. Only comparing is possible.



Share with Friends ( Sharing is Caring! )


Subscribe For E-mail Notification Of Article Updates

Enter your email address:

NOTICE:
DO NOT FORGET TO CLICK ON THE VERIFICATION LINK AFTER SUBSCRIBING,THE VERIFICATION MAIL WILL BE SENT TO YOU FROM "FeedBurner Email Subscriptions".
( What is this? Why I need to do this?)

Related Posts

One response. Wanna say something?

  1. Anurag Chitnis
    Apr 7, 2012 at 18:32:57
    #1

    useful information… thank u!

    [Reply]

Post a Comment

OR