Q:

How to mail a md5 password in php?

i am using md5 for passwords and storing it in MySQL.I don't have problems logging in but what i need is, i want to mail the exact password which user enters during registration to his mail id.how can i get back the password and send it to mail?
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// encrypt password
$encrypted_mypassword=md5($mypassword);

A:

To answer your question directly, you can send the user's "initial password" this way (assuming MD5 - but the logic is the same no matter what hashing algorithm you use).
$seed_password = $_POST['initial_password'];  // Save the user's selected password to this variable.
$hash_password = md5($seed_password); // This variable will now hold your hashed password.

// Save the $hash_password to the database.
#  YOUR CODE HERE

// Email the Seed Password (in the simplest manner possible).
mail('target@email.com' , 'Your new password' , 'Your new password is '. $seed_password);

This will email the value of the password before hashing.  Meanwhile, the hashed password will be stored in your database.
Now - when your user logs in, you're going to have to take the password they enter and HASH it before comparing it with the hashed value in your database.

