<?php

    session_start();
    include_once 'EncrypterUtil.php';
    $usrname = $_POST["username"];
    $pswd = $_POST["password"];
    //include 'common/connection.php';
    $servername = "localhost";
    $username = "finstech_sales";
    $password = "SalesApp@123";
    $dbname = "finstech_salesapp";
    
    //$str = "Sree@123";
    //$converter = new EncrypterUtil();
    //$encoded = $converter->encode($str );
    //$decoded = $converter->decode($encoded);
    
    try {
        $pdo = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
        $stmt = $pdo->prepare("select uid, username, password, status from authentication where username = ?");
        $stmt->execute([$usrname]); 
        $user = $stmt->fetch();
        if($user['password'] == $pswd){
            echo "Success";
            $_SESSION["isAuthenticated"] = "true";
        }else{
            echo "Invalid User";
        }
    }catch(PDOException $e) {
        echo $sql . "<br>" . $e->getMessage();
    }
    $pdo = null;
    
?>