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 ? Link to comment https://forums.phpfreaks.com/topic/103437-password-reset-code/ 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. Link to comment https://forums.phpfreaks.com/topic/103437-password-reset-code/#findComment-529680 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 Link to comment https://forums.phpfreaks.com/topic/103437-password-reset-code/#findComment-529689 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; ?? Link to comment https://forums.phpfreaks.com/topic/103437-password-reset-code/#findComment-529698 Share on other sites More sharing options...
hassank1 Posted April 29, 2008 Author Share Posted April 29, 2008 ? Link to comment https://forums.phpfreaks.com/topic/103437-password-reset-code/#findComment-529802 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. Link to comment https://forums.phpfreaks.com/topic/103437-password-reset-code/#findComment-530208 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.. Link to comment https://forums.phpfreaks.com/topic/103437-password-reset-code/#findComment-530335 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. Link to comment https://forums.phpfreaks.com/topic/103437-password-reset-code/#findComment-530388 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.