<?php

include 'db_connect.php';

$email = $_POST['email'];
$password = $_POST['password'];
$key = $_POST['key'];

$security_key = decrypData($key);

header('Content-Type: application/json; charset=utf-8');

if ($security_key == 'Jobayer121415' && strlen($email) > 0) {
    $con = dbConnect();

    $sql = "SELECT * FROM singup_table WHERE email = '$email' AND password = '$password'";
    $result = mysqli_query($con, $sql);
    
    if ($row = mysqli_fetch_assoc($result)) {
        echo json_encode([
            "status" => "success",
            "userid" => $row['id'], 
        ]);
    } else {
        echo json_encode([
            "status" => "error",
            "message" => "Password or email is incorrect"
        ]);
    }
} else {
    echo json_encode([
        "status" => "error",
        "message" => "Invalid security key"
    ]);
}


function decrypData($text) {
    $decoded = base64_decode($text);
    $decrypted = openssl_decrypt($decoded, 'AES-128-ECB', '0175526800812345', OPENSSL_RAW_DATA);
    return $decrypted;
}

?>
