Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. <?php
  2. require 'db.php';
  3. session_start();
  4.  
  5. if ($_SESSION['logged_in'] !=1 )
  6. {
  7. $_SESSION['message']="<div class='info-alert'>You must log in before changing your password!</div>";
  8. header("location: error.php");
  9. }
  10.  
  11. if (isset($_POST['change']) && $_POST['new_password'] != "" && $_POST['confirm_new_password'] && $_POST['current_password'] != "")
  12. {
  13. $email = $mysqli->escape_string($_SESSION['email']);
  14. $result = $mysqli->query("SELECT * FROM users WHERE email='$email'");
  15. $user = $result->fetch_assoc();
  16.  
  17. if (password_verify($_POST['current_password'], $user['password']))
  18. {
  19. $new_password = $mysqli->escape_string(password_hash($_POST['new_password'], PASSWORD_BCRYPT));
  20. $hash = $mysqli->escape_string(md5(rand(0,1000)));
  21. $sql = "UPDATE users SET password='$new_password', hash='$hash' WHERE email='$email'";
  22.  
  23. if ($mysqli->query($sql))
  24. {
  25. $_SESSION['message'] = "<div class='info-success'>Your password has been changed successfully!</div>";
  26. header("location: success.php");
  27. }
  28. }
  29. else
  30. {
  31. $_SESSION['message'] = "<div class='info-alert'>Please enter correct current password!</div>";
  32. header("Location: error.php");
  33. }
  34. }
  35. ?>
  36.  
  37. <!DOCTYPE html>
  38. <html>
  39. <head>
  40. <title>Change Your Password</title>
  41. <?php include 'css/css.html'; ?>
  42. <script src="js/validation.js" type="text/javascript"></script>
  43. </head>
  44. <body>
  45. <div class="form">
  46. <h1>Change Your Password</h1>
  47. <form id="changeform" name="changeform" action="changepassword.php" onsubmit="return change_validation();" method="post">
  48. <div class="field-wrap">
  49. <label>
  50. New Password<span class="req">*</span>
  51. </label>
  52. <input type="password" autocomplete="off" name="new_password" id="new_password"/>
  53. </div>
  54. <div class="field-wrap">
  55. <label>
  56. Confirm New Password<span class="req">*</span>
  57. </label>
  58. <input type="password" autocomplete="off" name="confirm_new_password" id="confirm_new_password"/>
  59. </div>
  60. <div class="field-wrap">
  61. <label>
  62. Current Password<span class="req">*</span>
  63. </label>
  64. <input type="password" autocomplete="off" name="current_password" id="current_password"/>
  65. </div>
  66. <span id="change_message"></span>
  67. <button class="button button-block" name="change" id="change"/>Change Password</button>
  68. </form>
  69. </div>
  70. <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
  71. <script src="js/index.js"></script>
  72. </body>
  73. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement