<?php

include_once 'functions.php';
session_start();
if (isset($_SESSION['uname'])) {
    $theclass = new passgen();
    $theclass->get();
}
?>
 <a href = "logout.php" style = "position:absolute; top: 10px; right:10px;">Logout</a>
        <script src = "script.js"></script>
    </head>
    
    <body>
        <a href = "logout.php" style = "position:absolute; top: 10px; right:10px;">Logout</a>
        <table>
        <form action = "home.php" method = "post">
            <tr><td>Website Name:</td><td><input type = "text" name = "website"></td></tr>
            <tr><td>UserName:</td><td><input type = "text" name = "genname"></td></tr>
            <tr><td>Genrate Password:</td><td><input type = "text" name = "genpass" id='genpass'>
            <button type="button" id='genrate'>Generate</button></td></tr>
            <tr><td></td><td><input type = "submit" name = "submit" value = "Save The Password."></td></tr>
         </form>
         </table>
        <?php 
    if ($_POST['submit']) {
        $name = $_POST['website'];
        $genname = $_POST['genname'];
        $genpass = $_POST['genpass'];
        $passgen = new passgen();
        $passgen->post($name, $genname, $genpass);
    }
    ?>
    </body>
    <?php 
} else {
    header('Location: index.php');
}
?>
</html>
include_once 'functions.php';
session_start();
if (isset($_SESSION['uname'])) {
    header('Location: home.php');
} else {
    ?>
    <head>
    <title>Welcome to PassGen</title>  
        <link rel = "stylesheet" href = "style.css">
    </head>
    
    <body>
        <?php 
    if (isset($_POST['submit'])) {
        $uname = $_POST['uname'];
        $pass = $_POST['pass'];
        $theclass = new passgen();
        $theclass->login($uname, $pass);
    }
    ?>
    <form action = "index.php" method = "post">
    <input type = "text" name = "uname"><br>
    <input type = "password" name = "pass"><br>
    <input type = "submit" name = "submit" value = "login">
    </form>
    </body>
    <?php 
}
?>
</html>
<?php

if (isset($_GET['gen'])) {
    include_once 'functions.php';
    $passgen = new passgen();
    echo $passgen->passgen();
}