professional-sql-01-public-files-forgotpass.php / php
<?php // include shared code include '../lib/common.php'; include '../lib/db.php'; include '../lib/functions.php'; include '../lib/User.php'; // construct password request form HTML ob_start(); ?> <form action="<?php echo htmlspecialchars(<p>Enter your username. A new password will be sent to the email address on file.</p> <table> <tr> <td><label for="username">Username</label></td> <td><input type="text" name="username" id="username" value="<?php if (isset(_POST['username'])) echo htmlspecialchars(</td> </tr><tr> <td> </td> <td><input type="submit" value="Submit"/></td> <td><input type="hidden" name="submitted" value="1"/></td> </tr><tr> </table> </form> <?php form = ob_get_clean(); // show the form if this is the first time the page is viewed if (!isset(GLOBALS['TEMPLATE']['content'] = // otherwise process incoming data else { // validate username if (User::validateUsername(_POST['username'])) { _POST['username']); if (!GLOBALS['TEMPLATE']['content'] = '<p><strong>Sorry, that ' . 'account does not exist.</strong></p> <p>Please try a ' . 'different username.</p>'; form; } else { // generate new password // send the new password to the email address on record message = 'Your new password is: ' . user->emailAddr, 'New password', GLOBALS['TEMPLATE']['content'] = '<p><strong>A new ' . 'password has been emailed to you.</strong></p>'; // store the new password password; // there was invalid data else { GLOBALS['TEMPLATE']['content'] .= '<p><strong>You did not ' . 'provide a valid username.</strong></p> <p>Please try ' . 'again.</p>'; form; } } // display the page include '../templates/template-page.php'; ?>
(C) Æliens 20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.