 <?php 
   require_once("head2Alt.php");
   if(isset($_POST['post']))

  {

    require_once("buda_connect.php");
    $con = new connect_class();
    $post=$_POST['post'];
    $ownID=$_POST['owniD'];
    $accountId=$_POST['owniD'];
         
      //CODE TO BE EXECUTED WHEN THE FORM SUBMITED///
    ////////////////////////
    if($post=="Save changes")
     {
      $password=$_POST['password'];
      $npassword=md5($_POST['npassword']);
      $cpassword=$_POST['cpassword'];
    if($con->vNcpassword($npassword,$cpassword) && $con->vNpassword($npassword)){
         $HD=$con->getMyPassword($ownID,$password);
          if($HD->rowCount()>0)
          {
               ?>
                <center>
                  
                  <font size="2" color="blue">
                   
                   <?php
              
                     echo $con->updateMyAccountPassword($ownID,$npassword);

                    ?>
                  </font>
                </center>
           <?php
               require_once"myAccountProfileAfterPost.php"; 
             }
             else{
               ?>
                <center>
                  
                  <font size="2" color="blue">
                   
                   <?php
              
             echo "Wrong password";
                  ?>
                  </font>
                </center>
           <?php

               require_once"myAccountProfileAfterPost.php";
             }
         }

    else{

          ?>
        
         <center>
            <div>
              <sup>
                <?php  
    
                   echo  $con->eNcpassword($npassword,$cpassword); 
                   echo  $con->eNpassword($npassword); 

                 ?>
              </sup>
           </div>
          </center>

<?php

           require_once"myAccountProfileAfterPost.php";

         }
      }

      //////////////
      /////////////////////////THE CODE TO BE EXECUTED IF THE FORM IS TO BE LOAD//////////////
      /////////////////////////////////////////////////////////////////

if($post=="Change password")
         {

     if(isset($_POST['owniD']))
     {
 
        

?> 
 
  
 
   <!--NEW USER REGISTRATION FORM, DISPLAYED BY DEFAULTS IN PAGE LOAD-->


<center><fieldset id="new_sevice_reg_form">
<label id="reg_form_tile_label">Change your account password here:- </label></p/>
 
<form name="new_user_registration" id="new_user_registration" action="changeMyAccountPassword.php" method="POST">

<table border="0" id="reg_form_table">

   <input class="hi" type="text" name="owniD"  value="<?php echo $ownID;?>"> 

        
    <tr>
  
  <td height="40px" width="35%" valign="top">

        <label id="mini_label">Current password:<sup>*</sup></label><br>

  </td> 


  <td id="reg_form_table_cell">
     
         <input type="password" name="password" id="password" class="prof_info"  /><br/>
         <sup id="pwd"></sup>
         
  </td>

   

</tr>
  
<tr>
  
  <td height="40px" width="35%" valign="top">

        <label id="mini_label">New password:<sup>*</sup></label><br>

  </td> 


  <td id="reg_form_table_cell">

         <input type="password" name="npassword" id="npassword" class="prof_info"  />
  <br/>
         <sup id="np"></sup>
         
  </td>

</tr>

<tr>
 
  <td height="40px"   valign="top">

        <label id="mini_label">Confirm password:<sup>*</sup></label><br>

  </td> 

  <td id="reg_form_table_cell">


    <input type="password" name="cpassword" id="cpassword" class="prof_info"  /><br/>

         <sup id="cp"></sup>
  </td>

  </tr>

   
<tr>

  <td colspan="2" align="center">
        <input type="submit"  name="post" value="Save changes" id="post"/>
  </td>

</tr>

</table>
 
</form>
</fieldset> </center>
 
<script>
 
$(document).ready(function(){
  
$("#new_user_registration").on('post',function(e){
 
var password =document.getElementById('password').value;
$.trim(password);

var npassword =document.getElementById('npassword').value;
$.trim(npassword);

var cpassword =document.getElementById('cpassword').value;
$.trim(cpassword);

 

 var pd =/[\(A-Za-z)]/;
  var  pw =/[\(0-9)]/;

var j=0,k=0, g=0,i=0; 
npassword=document.getElementById('npassword').value;
if(npassword==""){
 e.preventDefault();
document.getElementById('np').innerHTML="New password required !..";
 

                 }

 else{ 
       for (var i =0; i < npassword.length ; i++)
        {

             if(npassword[i].match(pd) )
             {
             j++;
             }
        }
         
        for (var i =0; i < npassword.length ; i++)
        {

             if(!npassword[i].match(pd) && !npassword[i].match(pw) )
             {
             k++;
             }
        }
         
          for (var i =0; i < npassword.length ; i++)
        {

             if(npassword[i].match(pw) )
             {
             g++;
             }
        }
         

        if(j<=0)
        {
        e.preventDefault();
         document.getElementById('np').innerHTML="Strong password must atleast letters mixed with digits"; 

              
         }
         
         else if(k>0)
         {
        e.preventDefault();
         document.getElementById('np').innerHTML="You typed unrequired character in a password"; 

         }
         else if(g<=0)
         {
            e.preventDefault();
            document.getElementById('np').innerHTML="Strong password must atleast one digits";

         }
         
         else
          {




                     if(npassword.length<8)
                        {
                     e.preventDefault();
                     document.getElementById('np').innerHTML="Valid password must contain 8 charracters.."; 
              

                        }

                        else
                        { 
                        document.getElementById('np').innerHTML="";

                         }
            }
          }
        
         
     
 
    j=0, i=0;k=0;g=0; 


                                                                           ///CONFIRM PASSWORD VALIDATION


 



if(cpassword=="")
{
e.preventDefault();
document.getElementById('cp').innerHTML="Confirm password!..";
 
}
 else if(cpassword!=npassword)
{
e.preventDefault();
document.getElementById('cp').innerHTML="Password mismatch!..";
 

 }

 else
 {

document.getElementById('cp').innerHTML="";
 }

 if(password=="")
{
e.preventDefault();
document.getElementById('pwd').innerHTML="Current password!..";
 
}
else{

document.getElementById('pwd').innerHTML="";
}
  
}
);
}
);  
    
 
</script>

<?php
    }
  }
}
 
require_once('footerIn.php');
?>


