I have a small community website and I need to implement some sort of forgotten password function. I currently store the passwords in the DB, encrypted with MD5
.
Is it possible to sort of 'decrypt' and send it to user via email or would I need to have a password reset page?
PHP Code to Send Forgotten Password by E-Mail Let's create a handler. php php script that will get form data is POST method. in the above code, The First check the POST superglobal is set & not empty and assign the submitted emailid to a variable. Check that username exists in the database using the select query.
WebSecurity - ResetPassword() The ResetPassword() method resets a user password using a password token.
In the search box on the taskbar, type create password reset disk, and then choose Create a password reset disk from the list of results. In the Forgotten Password wizard, select Next. Choose your USB flash drive and select Next. Type your current password and select Next.
php'; $username = $_POST['username']; $password = $_POST['password']; $newpassword = $_POST['newpassword']; $confirmnewpassword = $_POST['confirmnewpassword']; $result = mysql_query("SELECT password FROM user_info WHERE user_id='$username'"); if(!
An MD5 hashed password is not reversible. (MD5 is hashing, and not really encrypting, so there's a subtle difference). And yes you'll definitely want to provide a password "reset" process (and not simply email the password).
To give you a high level workflow for secure password resets...
To give you a little more detail into hashing...
When you hash a value like a password using the md5() function in PHP, the final value is going to be the same for that password no matter which server you run it on. (So there's one difference we can see right away between hashing and encryption... There's no private/public key involved).
So this is where you'll see people mention a vulnerability to rainbow tables. A very basic explanation of a rainbow table is... You md5() hash a bunch of dictionary words (weak passwords) in order to get their md5() hashed values. Put those in a database table (rainbow table).
Now, if you compromise a web site's database, you can run the users' hashed passwords against your rainbow table to (in essence) "reverse" the hash back to a password. (You're not really "reversing" the hash... But you get the idea).
That's where "salting" your passwords is best practice. This means (again, very basic idea here) that you append a random value to the users' passwords before you hash it. Now, when the rainbow table is run against your database, it's not as easily "reversed" because the md5() hash of "password" is different than "password384746".
Here's a nice SO Q/A that should help. Secure hash and salt for PHP passwords
According to this post The definitive guide to forms based website authentication, for step 3. and 4., I'm not sure you should send the same token you are storing.
I guess you must send the token, then hash it and stored the hashed token in DB. Otherwise, if your database is compromised, one can have access to the reset password page.
To summarize :
$token = md5(microtime (TRUE)*100000); $tokenToSendInMail = $token; $tokenToStoreInDB = hash($token);
where hash is a hashing algorithm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With