<?php

include(__DIR__ . '/../../config.php');

print_r($_POST);
if(isset($_POST['email_address'])){   
    
    
    $email_address = $_POST['email_address'];
    $password = $_POST['password'];
    $ciphering = "AES-128-CTR";
    $options = 0;
    $iv_length = openssl_cipher_iv_length($ciphering);
    $encryption_key = "Admin";
    $encryption_text = '1234567891011121';
    $encriptpassword = openssl_encrypt($password, $ciphering,
        $encryption_key, $options, $encryption_text);
    echo "Encrypted String: " . $encriptpassword . "\n";


    $query = "SELECT * FROM Admin WHERE email='$email_address' AND password='$encriptpassword' AND type='admin' ";
    $result = queryRunner($query);
    $row = rowRetrieverArray($result);
    echo "decripted String: " . $decryption . "\n";
    if($row['email']==$email_address && $row['password']==$encriptpassword){

        $decryption=openssl_decrypt ($row['password'], $ciphering,
            $encryption_key, $options, $encryption_text);


         session_start();
         $_SESSION['uid'] = $row['id'];
        $_SESSION['email'] = $row['email'];
        $_SESSION['password'] = $decryption;

        header("location:../admin_panel/index.php");

    }
    else{
        header("location:../admin_panel/login.php");
        ///var_dump($row);
    }
    
    
    
    
}
        
        
        
        
?>        