<?php
	include_once('../config.php');   
    
  
          
    if(!isset($_SESSION['userId']))
    { 
         header("Location: ../");
         die;
    }
    
    if(isset($_POST['submit']))
    {        
            
            
            
 
             
            $stmt=$conn->prepare("select pwd  from  UI__Rgst   where cuurentId=:cuurentId ");    
            $stmt->bindValue(':cuurentId', $_SESSION['userId'] , PDO::PARAM_STR); 
            $stmt->execute();   
            $FResult = $stmt->fetch(PDO::FETCH_OBJ);  
            $PWD =   hash('sha256', $_POST['oldPassword']);
             
           
            if($FResult->pwd==$PWD) 
            { 
                $stmt=$conn->prepare("update  UI__Rgst set  pwd=:password  where custId=:custId ");   
                $stmt->bindValue(':password', hash('sha256', $_POST['Password']) , PDO::PARAM_STR);  
                $stmt->bindValue(':custId', $_SESSION['userCustId'] , PDO::PARAM_STR); 
                $stmt->execute();     
                $_SESSION['Regis'] = "Password  Changed";
            }else
                $_SESSION['Regis'] = "Old Password Does Not Matched"; 
            
            header("Location: ChnagePassword.php");  
            die;
    }         
             
            $stmt=$conn->prepare("select  *   from  UI__Rgst where custId =:custId ");   
            $stmt->bindValue(':custId', $_SESSION['userCustId'] , PDO::PARAM_STR);  
            $stmt->execute(); 
            $FResult = $stmt->fetch(PDO::FETCH_OBJ);  
               
include_once("../view/dashboard/ChnagePassword.php");
?>