Guest User

Untitled

a guest
Mar 23rd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. function change_password($user) {
  2.  
  3. require('connect.php');
  4.  
  5. echo "<center><br/><hr/><br/><br/>
  6. <form action = account.php?action=cp method = 'POST'>
  7. Current Password :
  8. <input type = 'password' name = 'curr_pass'><br/>
  9. New Password :
  10. <input type = 'password' name = 'new_pass'><br/>
  11. Retype New Password :
  12. <input type = 'password' name = 'new_pass2'><br/>
  13. <input type = 'submit' name = 'change_pass' value = 'Change My password'><br/>
  14. </form>
  15. </center>";
  16.  
  17. //$flag = 0;
  18.  
  19. $curr_pass = @$_POST['curr_pass'];
  20. $new_pass = @$_POST['new_pass'];
  21. $new_pass2 = @$_POST['new_pass2'];
  22.  
  23. $sql1 = "
  24. SELECT password FROM forum.users
  25. WHERE username = ? LIMIT 1;
  26. ";
  27.  
  28. $stmt = $link->prepare($sql1);
  29. $stmt->bind_param('s' , $user);
  30. $stmt->execute();
  31. $stmt->bind_result($hashedPswd);
  32.  
  33. $stmt->fetch();
  34.  
  35. if(isset($_POST['change_pass']))
  36. {
  37. //$check = mysqli_query($link , "SELECT * FROM forum.users WHERE username = '".$_SESSION['username']."'");
  38.  
  39. if(crypt($curr_pass , $hashedPswd) == $hashedPswd )
  40. {
  41. if (strlen($new_pass) > 7)
  42. {
  43. if($new_pass == $new_pass2)
  44. {
  45. $password = encrypt_pswd($new_pass);
  46.  
  47. //$query = mysqli_query($link , "UPDATE users SET password = '".$new_pass."' WHERE username = '".$user."'");
  48.  
  49. $sql = "UPDATE users SET password = ? WHERE username = $user;";
  50.  
  51. $stmt2 = $link->prepare($sql);
  52. $stmt2->bind_param('s' , $password);
  53.  
  54. //$res = mysqli_query($link , $sql);
  55.  
  56. if($stmt2->execute())
  57. {
  58. echo "<h3 style='text-align:center; color:green;'>Your Password has been Changed </h3>";
  59. }
  60.  
  61. else
  62. {
  63. echo "<h3 style='text-align:center; color:red;'>Couldnot change your password</h3>";
  64. echo "Error is => " . mysqli_error($link);
  65. }
  66. }
  67.  
  68. else
  69. {
  70. echo "<h3 style='text-align:center; color:red;'>The two passwords do not match</h3>";
  71. }
  72. }
  73.  
  74. else
  75. {
  76. echo "<h3 style='text-align:center; color:red;'>New Password is too short</h3>";
  77. }
  78. }
  79.  
  80. else
  81. {
  82. echo "<h3 style='text-align:center; color:red;'>Your cuurent Password doesn't match with the typed password</h3>";
  83. }
  84.  
  85. }
  86.  
  87. }
  88.  
  89. $stmt = $link->prepare($sql);
  90. $stmt->bind_param('s' , $password);
Add Comment
Please, Sign In to add comment