Advertisement
Guest User

Untitled

a guest
Jul 20th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. <?php
  2. session_start();
  3. ?>
  4.  
  5. <html>
  6. <body>
  7.  
  8. <div style="margin:0 auto" align=center>
  9. <form>
  10. Username:<br>
  11. <input type="text" name="username"><br>
  12. Current Password:<br>
  13. <input type="password" name="password"><br>
  14. New Password:<br>
  15. <input type="password" name="newpassword"><br>
  16. Confirm Password:<br>
  17. <input type="password" name="confirmnewpassword"><br>
  18. <br>
  19. <input type="submit" name="submit" value="Submit" />
  20. </form>
  21.  
  22. <?php
  23.  
  24. $dbhost = "*****";
  25. $dbname = "*****";
  26. $dbuser = "*****";
  27. $dbpass = "*****";
  28. //Connect to database
  29.  
  30. $connect= mysql_connect ("$dbhost","$dbuser","$dbpass")or die("Could not connect: ".mysql_error());
  31. mysql_select_db("$dbname") or die(mysql_error());
  32.  
  33. if(isset($_POST['submit']))
  34.  
  35. $username = $_POST['username'];
  36. $password = md5($_POST['password']);
  37. $newpassword = md5($_POST['newpassword']);
  38. $confirmnewpassword = md5($_POST['confirmnewpassword']);
  39.  
  40. $result = mysql_query("SELECT password FROM accounts WHERE username='$username'");
  41.  
  42. $row = mysql_fetch_assoc($result);
  43.  
  44. $passworddb = $row['passoword']; //password from Data Base
  45. if(!$result)
  46. {
  47. echo "The username you entered does not exist";
  48. }
  49. if($password==$passworddb){
  50. if($newpassword==$confirmnewpassword){
  51. $sql=mysql_query("UPDATE accounts SET password='$newpassword' where username='$username'");
  52. ?> <script>
  53. alert('Password changed!');
  54. window.location.href='change_password.php';
  55. </script> <?php
  56. }
  57. else{
  58. ?> <script>
  59. alert('Error, new password and confirm password must be the same');
  60. window.location.href='change_password.php';
  61. </script> <?php
  62. }
  63. }
  64. ?>
  65. </body>
  66. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement