Guest User

Untitled

a guest
Aug 12th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. if (isset($_POST['password_change'])) {
  2. $hash = password_hash($password);
  3. $username = strip_tags($_POST['username']);
  4. $password = strip_tags($_POST['old_password']);
  5. $old_password = $hash;
  6. $newpassword = strip_tags($_POST['new_password']);
  7. $new_password = $hash;
  8. $confirmnewpassword = strip_tags($_POST['con_newpassword']);
  9. $con_newpassword = $hash;
  10.  
  11. $stmtUsers=$con->prepare("SELECT COUNT(*) FROM users where username=? limit 1");
  12. $stmtUsers->bind_param("s",$username);
  13.  
  14. if($stmtUsers->execute()) {
  15. $hash = $stmtUsers->fetch();
  16. if ($password == $hash['password']){
  17. if($newpassword == $confirmnewpassword) {
  18. $stmtUpdate=$con->prepare("UPDATE `users` SET `password` = ? WHERE `username` = ?");
  19. $stmtUpdate->bind_param("ss",$newpassword,$username);
  20. if($stmtUpdate->execute()){
  21. echo "¡Contraseña cambiada con éxito!";
  22. } else{
  23. echo "La contraseña no se pudo actualizar";
  24. }
  25. } else {
  26. echo "¡Las contraseñas no coinciden!";
  27. }
  28.  
  29. } else {
  30. echo "Por favor, escriba su contraseña actual con precisión!";
  31.  
  32. }
  33. } else {
  34. echo "Nombre de usuario incorrecto";
  35. }
  36. }
  37.  
  38. <form name="resetform" action="changepass.php" id="resetform" class="passform" method="post" role="form">
  39. <h3>Change Your Password</h3>
  40. <br />
  41. <input type="hidden" name="username" value="<?php echo $sname; ?>" ></input>
  42. <label>Enter Old Password</label>
  43. <input type="password" class="form-control" name="old_password" id="old_password">
  44. <label>Enter New Password</label>
  45. <input type="password" class="form-control" name="new_password" id="new_password">
  46. <label>Confirm New Password</label>
  47. <input type="password" class="form-control" name="con_newpassword" id="con_newpassword" />
  48. <br>
  49. <input type="submit" class="btn btn-warning" name="password_change" id="submit_btn" value="Change Password" />
  50. </form>
  51.  
  52. <!--display success/error message-->
  53. <div id="message"></div>
  54.  
  55. <script type="text/javascript">
  56. $(document).ready(function() {
  57. var frm = $('#resetform');
  58. frm.submit(function(e){
  59. e.preventDefault();
  60.  
  61. var formData = frm.serialize();
  62. formData += '&' + $('#submit_btn').attr('name') + '=' + $('#submit_btn').attr('value');
  63. $.ajax({
  64. type: frm.attr('method'),
  65. url: frm.attr('action'),
  66. data: formData,
  67. success: function(data){
  68. $('#message').html(data).delay(3000).fadeOut(3000);
  69. },
  70. error: function(jqXHR, textStatus, errorThrown) {
  71. $('#message').html(textStatus).delay(2000).fadeOut(2000);
  72. }
  73.  
  74. });
  75. });
  76. });
  77. </script>
Add Comment
Please, Sign In to add comment