Advertisement
Guest User

Untitled

a guest
Jul 19th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.  
  5. if ($_SESSION['username'])
  6. echo "Welcome, ".$_SESSION['username']."!<br><a href='logout.php'>Logout</a><p>";
  7. else
  8. die("You must be logged in!");
  9.  
  10.  
  11. $user = $_SESSION['username'];
  12.  
  13. if ($user)
  14. {
  15. //user is logged in
  16.  
  17. if ($_POST['submit'])
  18. {
  19. //check fields
  20.  
  21. $oldpassword = $_POST['oldpassword'];
  22. $newpassword = $_POST['newpassword'];
  23. $renewpassword = $_POST['renewpassword'];
  24.  
  25. // check password against db
  26.  
  27. // connect db
  28. $connect = mysql_connect("207.210.254.226","datacatch","oblivion") or die("couldn't connect");
  29. mysql_select_db("reborn") or die("couldnt find db");
  30.  
  31. $queryget = mysql_query("SELECT password FROM user WHERE Name='$user'") or die("Incorrect infomation");
  32. $row = mysql_fetch_assoc($queryget);
  33.  
  34. $oldpassworddb = $row['password'];
  35.  
  36. //check passwords
  37. if ($oldpassword==$oldpassworddb)
  38. {
  39.  
  40.  
  41. // check two new passwords
  42. if ($newpassword==$renewpassword)
  43. {
  44.  
  45. //success
  46. //change password in db
  47.  
  48.  
  49. $querychange = mysql_query("
  50. UPDATE user SET password='$newpassword' WHERE Name='$user'
  51. ") or die("Did not work!");
  52. session_destroy();
  53. die("Your password has been changed. <a href='index.php'>Click here</a> to return to Login");
  54.  
  55. }
  56. else
  57. die("New Passwords don't match, please try again.");
  58.  
  59. }
  60. else
  61. die("Old Password Incorrect, please try again.");
  62.  
  63. }
  64. else
  65. {
  66.  
  67. echo"
  68. <form action='member.php' method='POST'>
  69. Old password: <input type='text' name='oldpassword'><p>
  70. New password: <input type='password' name='newpassword'><br>
  71. Repeat New password: <input type='password' name='renewpassword'><p>
  72. <input type='submit' name='submit' value='Change Password'>
  73. </form>
  74. ";
  75.  
  76. }
  77. }
  78. else
  79. die("You must be logged in to change your username/password");
  80.  
  81.  
  82.  
  83. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement