Article focus on simple way how to recover access to a page for user that forgotten password. Introduced solution generate new password, reset old and send them to the user on registration e-mail.
Expectation from password recovery mechanism
After longer period of user inactivity any user can feel difficulties to log in into their own account. All well planed pages must have functionality for password recovery. Simple way how to do it, is resend new password to a registration e-mail of the user.
This solution can be further hardened by expectation of change user password after gainig first access with send password (user must change to their own password).
All new solution incorporate two way authentication or use second verification by sending code to mobile phone or mobile application for assuring legitimity of password resend.
For smooth user experience is necessary provide functional UI on rsend form. Our application implement this feature way that you can see on following pictures.
As you can see after providing valid e-mail address, new pasword is created, inserted into a database and send via e-mail. But this is our simple solution, how to mitigate rough client that will request reset working password. This is only one field for further hardening of this functionlity.
On next rows we take look on way how we implemented this feature to existing page code.
Implementation of password recovery feature
Full code responsible for validation of provided e-mail for password recovery. Recreation of password, inserting them into a database as hash and sending as plain text within a e-mail to user and notification of success or failure on any of the working stage is as follow.
// user is not loged and e-mail was good submited and there display info about sucessfull resend e-mail
echo ‚<br>‘;
echo ‚<p class=“alert alert-success“> For your account‘ . $username. ‚ we provided new password.</em></p>‘; // session solution
echo ‚<p class=“alert alert-success“> Provided password has been sent in to e-mail <em>‘ . $e_mail. ‚</em> used during resistration of your account. </p>‘; // session solution
echo ‚<p class=“alert alert-success“> We recommend you change them after first successful login on edit profile page. </a></p>‘;
} else {
// user is loged in – there is no need for resend password
echo ‚<br>‘;
echo ‚<p class=“alert alert-success“> You are loged in as <em>‘ . $_SESSION[‚username‘]. ‚</em></p>‘; // session solution
echo ‚<p class=“alert alert-success“> There is <em>no need</em> for resend new password. </p>‘; // session solution
echo ‚<p class=“alert alert-success“> If you will logout or login with another credentials, please first <a href=“logout.php“>logout!. </a></p>‘;
}
?>
</div>
<?php // footer include code
require_once(‚footer.php‘); // including footer
generate_footer(580); // function from footer.php for seting width, you can use 580 and 1060px width
?>
</body>
</html>
Conclusion
Password resend functionality conclude demonstration of implementation features to our bazaar app. This series introduces older functional approach for use of php scripting. All bigger projects stand on MVC object oriented concept with support of php frameworks. Please look at our introduction as on demonstration how to do some interactive webpages with php server scripting for absolute beginners with focus on further study. Our big next goal is focus on object oriented programming and new way how to write more reusable code on the future.
All code of bazaar demonstration app can be obtained from github here.
We inform you that we use cookies and other technologies on this site to function and improve the operation of the site, ensure it, provide social networking features, personalize content and ads to users, and analyze traffic and user behavior. For more information, please read our Terms of Use and Cookies. You can prevent cookies from being processed by changing the settings in your Internet browser.OkPrivacy policy