使用MongoDB和PHP

We assigned me a new project to realize in order to manage candidacies of customers !

3 tasks will be realized :

  • authentification of the users

  • import data concerning the candidacy in the form of file .xls/.xlsx thanks to the upload of files.

  • Display the results in json format

I thus chose to realize it in HTML / CSS, Javascript / JQuery, PHP as well as a basebasis NoSql MongoDB.

On one hand, the users will be inserted in base(basis) in a manual way by the style: db.users.insert({"name": "Laurence", "password": hex_md5("test")});

Do not ask me why they will be inserted in this way, it is the person in charge who so decided :(

The problem already is that I did not find in a more secure way, to insert passwords that other than with the function hex_md5 ().

Thus if already you could help me on this point, it would be already good ! :)

On the other hand, to communicate my database with PHP, I use the class MongoDB\Driver\Manager.

Already of the evil to be able to implement and to use this kind of classes, seen that the syntax is a little bit different from the PDO:/

I try through a page of authentification, to verify if the seized fields correspond well to the values in database to be able to connect, but top I already surround :/

If somebody could give me a blow onto these points, it would be top! :D

And if somebody would have some documentation to propose, it is always good to set seen that I can't find any other record of it :/

<html>
    <head>
        <meta charset="utf-8">
        <title>Login</title>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
        <script src="../js/login.js"></script>
        <link rel="stylesheet" href="../css/login.css">
    </head>
    <body>
        <?php
        include('../index.php');
        ?>
        <form method="post" action="../templates/checkLogin.php">
            <div class="container">
                <div class="card card-container">
                    <img id="profile-img" class="profile-img-card" src="../img/avatar.png" />
                    <p id="profile-name" class="profile-name-card"></p>
                    <form class="form-signin">
                        <span id="formIdentity" class="formIdentity"></span>
                        <input type="text" id="identity" name="identity" class="form-control" placeholder="Your identity" autofocus>
                        <input type="password" id="password" name="password" class="form-control" placeholder="Your password">
                        <button class="btn btn-lg btn-primary btn-block btn-signin" type="submit" id="submitBtn" onclick="checkForm(this)">Sign in</button>
                    </form><!-- /form -->
                    <a href="../templates/forgotPassword.php" class="forgot-password">
                        Forgot password ?
                    </a>
                </div><!-- /card-container -->
            </div><!-- /container -->
        </form>
    </body>
</html>

<?php
$manager = new MongoDB\Driver\Manager();

$filter = ['x' => ['$gt' => 1]];
$options = [
    'projection' => ['_id' => 0],
    'sort' => ['x' => -1],
];

$query = new MongoDB\Driver\Query(array(), $options);
$cursor = $manager->executeQuery('candidates.users', $query);

foreach ($cursor as $document)
{
if($document->name === $_POST['identity'] && 

password_verify($_POST['password'], $document->name))
    {
        echo "User ".htmlspecialchars($_POST['identity']). "connected !";
    }
    else
    {
        echo "Unknown user !";
    }
}
?>

enter image description here

enter image description here

</div>