Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. <?php
  2. require 'require/sharedVar.php';
  3. require 'require/functions.php';
  4. require 'require/connect.php';
  5. require 'require/error_reporting.php';
  6.  
  7. // Check to see if user has posted the information
  8. if (isset($_POST['update']) && trim($_POST['update']) != '') {
  9. if (isset($_POST['old_username']) && isset($_POST['old_password'])
  10. && trim($_POST['old_username']) != '' && trim($_POST['old_password']) != '') {
  11.  
  12. // Save and check old username and password
  13. $old_username = escape_quotes($_POST['old_username']);
  14. $old_password = escape_quotes(hash("sha512", $_POST['old_password']));
  15.  
  16. $user = get_all_info("SELECT * FROM users WHERE Username='$old_username'");
  17.  
  18. // Get the first instance of the user and store it into an array
  19. $userArray = $user->fetch_assoc();
  20.  
  21. if(count($userArray) <= 0) {
  22. die("<h2>That username doesn't exist! Please type in the correct username.
  23. <a href='update.php'>Back</a></h2>");
  24. }
  25. if ($userArray['Password'] != $old_password) {
  26. die("<h2>Incorrect password! <a href='update.php'>Back</a></h2>");
  27. }
  28.  
  29. $new_name = '';
  30. if ($_POST['new_name']) {
  31. // Get the existing name if users input the name
  32. $old_name = $userArray['Name'];
  33.  
  34. $new_name = escape_quotes(strip_tags($_POST['new_name']));
  35.  
  36. insert_or_update_info("UPDATE users SET Name='$new_name'
  37. WHERE Name='$old_name'");
  38.  
  39. echo "<h2>Name has been updated. Please <a href='login.php'>log in</a> with your new credentials. </h2><br>";
  40. } else {
  41. echo "<h2>Since no Name was given, Name is still " . $userArray['Name'] . "</h2><br>";
  42. }
  43. // Check new username if user put it
  44. if (trim($_POST['new_username']) != '' && isset($_POST['new_username']) ) {
  45. $new_username = escape_quotes(strip_tags($_POST['new_username']));
  46.  
  47. $check = get_all_info("SELECT * FROM users WHERE Username='$new_username'");
  48. // Get the first instance of the user and store it into an array
  49. $userArray = $check->fetch_assoc();
  50.  
  51. if (count($userArray) > 0) {
  52. die("<h2>That username already exists! Try creating another username.
  53. <a href='register.php'>Back</a></h2>");
  54. }
  55. if (!ctype_alnum($new_username)) {
  56. die("<h2>Username contains special characters! Only numbers and letters
  57. are permitted. <a href='update.php'>Back</a></h2>" );
  58. }
  59. if (strlen($new_username) > 20) {
  60. die("<h2>Username must contain less than 20 characters.
  61. <a href='update.php'>Back</a></h2>" );
  62. }
  63.  
  64. insert_or_update_info("UPDATE users SET Username='$new_username'
  65. WHERE Username='$old_username'");
  66.  
  67. echo "<h2>Username has been updated. Please <a href='login.php'>log in</a> with your new credentials. </h2><br>";
  68. } else {
  69. echo "<h2>Since no Username was given, Username is still " . $userArray['Username'] . "</h2><br>";
  70. }
  71.  
  72. // Check new password
  73. if (trim($_POST['new_password']) != '' && isset($_POST['new_password'])) {
  74.  
  75. $new_password = escape_quotes(hash("sha512", $_POST['new_password']));
  76.  
  77. insert_or_update_info("UPDATE users SET Password='$new_password'
  78. WHERE Password='$old_password'");
  79.  
  80. echo "<h2>Password has been updated. Please <a href='login.php'>log in</a> with your new credentials. <h2><br>";
  81. } else {
  82. echo "<h2>Since no Password was given, Password remains the same. </h2><br>";
  83. }
  84. }
  85. else {
  86. echo "<h2>Please enter a username and password.</h2>";
  87. }
  88. }
  89. require_once 'require/login_check.php';
  90. ?>
  91. <!doctype html>
  92. <html>
  93. <head>
  94. <?php include "includes/head.php" ?>
  95. </head>
  96. <body>
  97. <div id="container">
  98. <?php include "includes/header.php" ?>
  99. <?php include "includes/nav.php" ?>
  100. <h1>Update Information</h1>
  101. <form method="post" action="">
  102. <ul>
  103. <li>
  104. <label for="old_username">Enter Existing Username</label>
  105. <input id="old_username" type="text" name="old_username" value="" />
  106. </li>
  107. <li>
  108. <label for="old_password">Enter Existing Password</label>
  109. <input id="old_password" type="text" name="old_password" value="" />
  110. </li>
  111. <li>
  112. <label for="new_username">Enter New Username</label>
  113. <input id="new_username" type="text" name="new_username" value="" />
  114. </li>
  115. <li>
  116. <label for="new_password">Enter New Password</label>
  117. <input id="new_password" type="password" name="new_password" value=""/>
  118. <li>
  119. <li>
  120. <label for="new_name">Enter New Name</label>
  121. <input id="new_name" type="text" name="new_name" value=""/>
  122. <li>
  123. <input type="submit" name="update" value="update">
  124. </li>
  125. </ul>
  126. </form>
  127. <?php include 'includes/footer.php' ?>
  128. </div>
  129. </body>
  130. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement