SHARE
TWEET

Php

a guest Aug 13th, 2019 128 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <?php
  3.     $host = "localhost";  
  4.     $username = "root";  
  5.     $password = "";  
  6.     $database = "PDOtesting";  
  7.     $message = "";  
  8.     try  
  9.     {  
  10.       $connect = new PDO("mysql:host=$host; dbname=$database", $username, $password);  
  11.       $connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  12.  
  13.         if(isset($_POST['re_password'])) {
  14.  
  15.             $old_pass=$_POST['old_pass'];
  16.             $new_pass=$_POST['new_pass'];
  17.             $re_pass=$_POST['re_pass'];
  18.  
  19.             // User confirm old password authentication  
  20.                 $query = "SELECT * FROM users WHERE username = :username LIMIT 1";  
  21.                 $statement = $connect->prepare($query);  
  22.                 $statement->execute(  
  23.                      array(  
  24.                           'username'     =>     $login_session  
  25.                      )  
  26.                 );  
  27.                 $count = $statement->rowCount();
  28.  
  29.                 if($count > 0)  
  30.                 {  
  31.                      $result = $statement->fetch();
  32.  
  33.                     //check old password if correct
  34.                     if (password_verify($_POST["old_pass"], $result['old_pass'])) {
  35.                          // if password correct
  36.                         if ($new_pass == $re_pass) {
  37.  
  38.                             $query2 = "UPDATE users SET password = :password WHERE username = :username";
  39.  
  40.                             $hash = password_hash($re_pass, PASSWORD_DEFAULT);
  41.  
  42.                             $statement = $connect->prepare($query2);  
  43.                             $statement->execute(  
  44.                                 array(  
  45.                                     'username'     =>     $login_session,
  46.                                     'password'     =>     $hash
  47.                                 )  
  48.                             );
  49.  
  50.                             echo "<script>alert('Changed Password Sucessfully! You will be logged out from this page'); window.location='../session_destroy.php'</script>";
  51.  
  52.                         }
  53.  
  54.                         else {
  55.                             echo "<script>alert('new password and repeat password does not match!'); window.location='change_password.php'</script>";
  56.                         }
  57.                     }} else {
  58.                         echo "<script>alert('Your old password is incorrect'); window.location='change_password.php'</script>";
  59.                     }
  60.  
  61.                 // $data_pwd=$chg_pwd1['password'];
  62.         }
  63.     }
  64.     catch(PDOException $error)  
  65.     {  
  66.       $message = $error->getMessage();  
  67.     }
  68.     ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top