<?php
 
$row = $__user;

if((isset($row['acone']) && $row['acone']== 1 && isset($_GET['otps']) == 'true') || (isset($row['actwo']) && $row['actwo']== 1 && isset($_GET['otps']) == 'true')){

  


  $date = $_SESSION['date'];
  $bname = $_SESSION['bname'];
  $bbn = $_SESSION['bbn'];
  $bv = $_SESSION['bv'];
  $swift = $_SESSION['swift'];
  $amount =  $_SESSION['amount'];
  $comments = $_SESSION['comments'] ;
  $tacctno = $_SESSION['tacctno '];
  $toption = $_SESSION['toption'];
  $desc = $_SESSION['description'] ;



$mobile_no= $_SESSION['phone'];

$rand_opt = substr(str_shuffle("0123456789"), 0, 5);
  
  
//twillio
$sid = "AC52f7d28985fc78b08f87652359e1babd"; // Your Account SID from www.twilio.com/console
$token = "602fcf9812a835ac3b573dd395bfe537"; // Your Auth Token from www.twilio.com/console

$client = new Twilio\Rest\Client($sid, $token);
$message = $client->messages->create(
     '+'.$mobile_no, array(
   'from' => '+13197748578', // From a valid Twilio number
     'body' => 'Welcome To  '.$name.', Your transfer verification Code is  ' . $rand_opt
  )
);



if ($message->sid) {
    $otp_store = password_hash($rand_opt, PASSWORD_DEFAULT);
    $sql = "UPDATE tbl_users SET otp_hash = '$otp_store' , phone = '$mobile_no' WHERE id = $user_id AND acctno = $acctno";
    if ($link->query($sql)) {
       $msg = "otp code has been sent to your phone !";
    }
}
}











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


  
  $_SESSION['input_otp'] = preg_replace('/[^0-9]/', '', $_POST['token']);
     
  $input_otp = $_SESSION['input_otp'];

      $sql1 = "SELECT * FROM tbl_users WHERE id = $user_id AND acctno = $acctno";
      
      $result1 = mysqli_query($link, $sql1);
      if(mysqli_num_rows($result1) > 0){
          while ($row = mysqli_fetch_assoc($result1)){

          $pass_hash_fromdb = $row['otp_hash'];
               

          if (password_verify($input_otp, $pass_hash_fromdb)) {

            

            echo '<script type="text/javascript">
            window.location.href ="im.php" ;
            </script>';
        
            $input_otp = $_SESSION['input_otp'];
  }else{
  
  
  $msg = "Invalid OTP Code!";
  
  }
  } 
      }

    }



