Advertisement
Guest User

Untitled

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