PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/mybookbag/passreset.php

https://bitbucket.org/s2223902/mybookbag
PHP | 191 lines | 189 code | 2 blank | 0 comment | 1 complexity | e212825f88ee9d1f006ebc07767d895e MD5 | raw file
  1. <?php
  2. session_start();
  3. include('db_connection.php');
  4. include('functions.php');
  5. ?>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7. <html xmlns="http://www.w3.org/1999/xhtml">
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  10. <link rel="stylesheet" href="css/formstyles.css" type="text/css" />
  11. <link href='http://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
  12. <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
  13. <script type="text/javascript" src="js/Placeholders.js"></script>
  14. <script type="text/javascript">
  15. Placeholders.init({
  16. live: true,
  17. hideOnFocus: true});
  18. </script>
  19. <link href="css/toolbar.css" rel="stylesheet" type="text/css" />
  20. <title><?php echo $_SESSION['username'];?>'s Settings</title>
  21. </head>
  22. <body>
  23. <?php include ("php/random-bg.php"); ?>
  24. <div id="mainContainer">
  25. <div id="carbonForm2">
  26. <div id="logo2">
  27. <img src="img/logo.png" />
  28. <p>Welcome <b><?php echo $_SESSION['username'];?></b></p>
  29. </div>
  30. <ul id="nav">
  31. <li><a href="page.php">Home</a></li>
  32. <li><a href="mybooks.php">MyBookBag</a>
  33. <ul>
  34. <li><a href="mybooks.php">My Books</a></li>
  35. <li><a href="myebooks.php">My eBooks</a></li>
  36. <li><a href="myjournals.php">My journals</a></li>
  37. <li><a href="adddoc.php">Add Books</a></li>
  38. </ul>
  39. </li>
  40. <li><a href="friends.php">My Friends</a>
  41. <ul>
  42. <li><a href="friends.php">My Friends</a></li>
  43. <li><a href="messages.php">Messages (<?php echo checkMessages();?>)</a></li>
  44. <li><a href="addfriend.php">Add friends</a></li>
  45. <li><a href="requests.php">Friend Requests</a></li>
  46. </ul>
  47. </li>
  48. <li class="current"><a href="settings.php">Settings</a>
  49. <ul>
  50. <li><a href="passreset.php">Change Password</a></li>
  51. </ul>
  52. </li>
  53. <li><a href="contact.php">Contact</a></li>
  54. <li><a href="logout.php">Log Out</a></li>
  55. </ul>
  56. <div class="fieldContainer">
  57. <h1>Settings</h1>
  58. <h3>Updating Password</h3>
  59. <br>
  60. <hr>
  61. <br>
  62. <?php
  63. //We check if the user is logged
  64. if(isset($_SESSION['username']))
  65. {
  66. $form = true;
  67. $opassword = '';
  68. $opassword2 = '';
  69. $opassword3 = '';
  70. if(isset($_POST['password'], $_POST['password2'], $_POST['password3']))
  71. {
  72. $opassword = $_POST['password'];
  73. $opassword2 = $_POST['password2'];
  74. $opassword3 = $_POST['password3'];
  75. //We remove slashes depending on the configuration
  76. if(get_magic_quotes_gpc())
  77. {
  78. $opassword = stripslashes($opassword);
  79. $opassword2 = stripslashes($opassword2);
  80. $opassword3 = stripslashes($opassword3);
  81. }
  82. //We check if all the fields are filled
  83. if($opassword2 == $opassword3)
  84. {
  85. //We protect the variables
  86. $password = mysql_real_escape_string($opassword);
  87. $password2 = mysql_real_escape_string($opassword2);
  88. $password3 = mysql_real_escape_string($opassword3);
  89. //We update the password
  90. $PasswordHash = md5($password);
  91. $PasswordHash3 = md5($password3);
  92. $query_change_credentials = "update `users` set `password`='$PasswordHash3' where `id`={$_SESSION["id"]} and `password`='$PasswordHash'";
  93. $result_check_credentials = mysql_query($query_change_credentials);
  94. if($result_check_credentials)
  95. {
  96. ?>
  97. <div class="message">The password has been succesfully updated<br />
  98. <a href="settings.php">Back to settings</a></div>
  99. <?php
  100. $form = false;
  101. }
  102. else
  103. {
  104. //Otherwise, we say that an error occured
  105. $error = 'An error occurred while updating password';
  106. }
  107. }
  108. else
  109. {
  110. //Otherwise, we say the passwords do not match
  111. $error = 'The passwords do not match';
  112. }
  113. }
  114. else
  115. {
  116. //Otherwise, we say a field is empty
  117. $error = 'Please fill in the fields to update password';
  118. }
  119. if($form)
  120. {
  121. //We display a message if necessary
  122. if(isset($error))
  123. {
  124. echo '<div class="message">'.$error.'</div>';
  125. }
  126. //We display the form
  127. ?>
  128. <form action="passreset.php" method="post" id="registration_form">
  129. <br />
  130. <div class="formRow">
  131. <div class="field">
  132. <input type="password" name="password" id="password" placeholder="Current Password" />
  133. </div>
  134. </div>
  135. <div class="formRow">
  136. <div class="field">
  137. <input type="password" name="password2" id="password2" placeholder="New Password" />
  138. </div>
  139. </div>
  140. <div class="formRow">
  141. <div class="field">
  142. <input type="password" name="password3" id="password3" placeholder="Retype Password" />
  143. </div>
  144. </div>
  145. <br>
  146. Back to <a href="settings.php">settings</a>.
  147. </div> <!-- Closing fieldContainer -->
  148. <div class="signupButton">
  149. <input type="submit" name="formsubmitted" id="submit" value="Change Password" />
  150. </div>
  151. </form>
  152. </div>
  153. </div>
  154. <?php
  155. }
  156. }
  157. else
  158. {
  159. echo '<div class="message">You must be logged to access this page.</div>';
  160. }
  161. ?>
  162. </div>
  163. </body>
  164. </html>