  <?php
 require_once"labClass.php";
  $con=new labClass();

 // $row=$con->getRowCount();                                                                //FUNCTION FOR VISITORS OF HOTEL HERE
  //$nr=$row->rowCount()+1;
///
?>
 
 <div class="container mt-3">
 
  <h6>Change password:</h6> 
   <div class="row">
  <div class="col">
      <div class="form-floating mb-3 mt-3"> 
      <input type="email" class="form-control" id="email" value="@gmail.com" width="30%"   name="email" required>
       <label for="email">Email:</label>
      <sup class="text-danger" id="em"> </sup>
    </div>
  </div>
    <div class="col">
  <div class="form-floating mb-3 mt-3"> 
      <input type="password" class="form-control" id="opwd" value="" placeholder="Enter password" name="opwd" required>
       <label for="opwd">Password</label>
      <sup class="text-danger" id="opw"> </sup>
    </div> 

    </div>
  </div>
  <div class="row">
  <div class="col">
  <div class="form-floating mb-3 mt-3"> 
      <input type="password" class="form-control" id="pwd" value="" placeholder="Enter password" name="pwd" required>
       <label for="pwd">Password</label>
      <sup class="text-danger" id="pw"> </sup>
    </div> 

    </div>
    
 
    <div class="col">


   <div class="form-floating mb-3 mt-3"> 
      <input type="password" class="form-control" id="cpwd" value="" placeholder=" password" name="cpwd" required>
       <label for="pwd">Confirm password</label>
      <sup class="text-danger" id="cpw"> </sup>
    </div>
  </div>
  </div>
  <div class="row">
    <div class="col">
   
 
     </div>
     <div class="col">
     <input type="submit" class="btn btn-primary" id="submit" name="submit" style="height:60PX;" onclick="saveEData();" value="Submit"/>
 
    </div>
</div> 
</div> 
<script> 
 function saveEData(){ 
var ecc=0;  
 

var submit =document.getElementById('submit').value;
$.trim(submit);
var email =document.getElementById('email').value;
$.trim(email);
var opassword =document.getElementById('opwd').value;
$.trim(opassword);

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

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

  

var vN =/[\(A-Za-z)]/g; 

var nV =/[a-z\s]/i;
  var j=0,k=0, g=0,i=0;

                                                         //FIRST NAME VALIDATION
 
var mail=/[\(A-Za-z)][\w.]\w+@\w+\.(net|com|edu)/;
if(email==""){
  ecc++; 
document.getElementById('em').innerHTML="E-mail address is required!..";
 

             }
 else{
  
         if(!email.match(mail))
          {
          ecc++;
        //e.preventDefault();
        document.getElementById('em').innerHTML="Invalid email"; 
              }
         else{ 

        document.getElementById('em').innerHTML="";

              }
   }
 
 
    j=0, i=0;
               

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

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

if(opassword=="")
{
//e.preventDefault();
document.getElementById('opw').innerHTML="Old password required!..";
 
}
 else
 {

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


if(password==""){
 //e.preventDefault();
document.getElementById('pw').innerHTML="Password is required !..";
 
 ecc++;
                 }

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

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

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

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

        if(j<=0)
        { 
          ecc++;
         document.getElementById('pw').innerHTML="Strong password must contain atleast letters mixed with digits"; 

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

         }
         else if(g<=0)
         {
            ecc++;
            document.getElementById('pw').innerHTML="Strong password must contain atleast one digits";

         }
         
         else
          {




                     if(password.length<8)
                        {
                      ecc++;
                     document.getElementById('pw').innerHTML="Valid password must contain 8 charracters.."; 
              

                        }

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

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


                                                                           ///CONFIRM PASSWORD VALIDATION


 



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

 }

 else
 {

document.getElementById('cpw').innerHTML="";
 }
  
    if(ecc==0)
    {
      //alert("Error found:"+ecc);
        $.post("changepwdPro.php",
          {submit:submit,opassword:opassword,password:password,email:email},
          function(data){
      $('#disp').html(data).show();

    });
    }


 
//}
//);
//}
}
//);

</script>