function setpw() { try { $P = new Password(); $pass_exists = $P->exists(); } catch(Exception $e) { die($e->getMessage()); } if($_POST['newpass']) { if($pass_exists && !$P->isValid($_POST['password'])) { $pass_incorrect = true; } else { $confirm_failed = $_POST['newpass'] != $_POST['passconfirm']; // (Try to) set the password if(!$confirm_failed) { try { $set_pass = $P->set($_POST['newpass'], $db); } catch(Exception $e) { die($e->getMessage()); } } } } ?> <!DOCTYPE html> <html> <head><title>set scraps password</title></head> <body> <?php if($pass_incorrect): ?> <p>The password entered does not match the current password.</p> <?php elseif($set_pass): ?> <p>Password set successfully.</p> <?php else: ?> <?php if($confirm_failed): ?> <p>The passwords you entered don't match.</p> <?php endif; ?> <form method="post"> <?php if($pass_exists): ?> <input name="password" type="password" placeholder="Current password?" \> <?php endif; ?> <input name="newpass" type="password" placeholder="New password"\> <input name="passconfirm" type="password" placeholder="Confirm new password" \> <input type="submit" value="Set Password" /> </form> </body> </html> <?php endif; }