hassank1 Posted April 29, 2008 Share Posted April 29, 2008 Hi I want to add to my site (forget your password?) link .. where users can reset their password after receiving a reset email .. but I want to know what's the algorithm to do that ? Quote Link to comment Share on other sites More sharing options...
Rohan Shenoy Posted April 29, 2008 Share Posted April 29, 2008 1. Ask the user to type his "old" password and "new" password in a form and send the details to the PHP script. 2. If "old" password matches the one stored in db, then run an UPDATE query to replace the old password with new password. Quote Link to comment Share on other sites More sharing options...
Lumio Posted April 29, 2008 Share Posted April 29, 2008 But what if the old password got forgotten. Generate a random hash like this: <?php $s = ""; for($i=0;$i<10;$i++) { microtime()*30000; $s .= chr(rand(0,255)); } $randomHash = md5($s); ?> Save that random hash in your database with the current unix time to limit it by 24 hours. Send an email with the link to get a new password like... getnewpw.php?userid=4&hash=THE-RANDOM-HASH Quote Link to comment Share on other sites More sharing options...
hassank1 Posted April 29, 2008 Author Share Posted April 29, 2008 what's the purpose of using : microtime()*30000; ?? Quote Link to comment Share on other sites More sharing options...
hassank1 Posted April 29, 2008 Author Share Posted April 29, 2008 ? Quote Link to comment Share on other sites More sharing options...
Lumio Posted April 30, 2008 Share Posted April 30, 2008 if you use rand more than only once, it can happen, that you get the same number. To get around I used a command, that takes a short while. Quote Link to comment Share on other sites More sharing options...
hassank1 Posted April 30, 2008 Author Share Posted April 30, 2008 Okay I got your point about the same number issue ... but what's the realtion between "microtime()*30000" and the "short while" I mean what this code do exactly ? thx.. Quote Link to comment Share on other sites More sharing options...
Lumio Posted April 30, 2008 Share Posted April 30, 2008 This line just multiplies the value of microtime by 30000 You can also write 100000*1234556.65 This line just makes the server a little busy. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.