-1
Hello, I would like to know the best way to select and verify the password hash(password) in a database and compare with the password entered by the user in a login form. Is it more appropriate to store salt in the BD ? In the example below I created the password hash before selecting in the database:
<?php
include('conf.php');
$email = '[email protected]';
$senha = 'lala.123';
$custo = '08';
$salt = 'Cf1f11ePArKlBJomM0F6aJ';
$hash = crypt($senha, '$2a$' . $custo . '$' . $salt . '$');
    $query_select = "SELECT email, password FROM usuarios WHERE email = '$email' AND password = '$hash'";
    $select = mysqli_query($conexao,$query_select);
    if (mysqli_num_rows($select) == 1) {
        echo "Login Permitido";
    }
    else {
        echo "Login ou senha invalidos";
    } ?> 
Already in this example I selected the hash in the database to then compare with the password entered in the form using password_verify():
<?php 
#----------------- INCLUDING FILE --> "conf.php"
include('conf.php');
    if (isset($_POST['submit'])) {
        $email = mysqli_real_escape_string($conexao, $_POST['email']);
        $password = mysqli_real_escape_string($conexao, $_POST['password']);
        $query_select_email = "SELECT email FROM usuarios WHERE email = '$email'";
        $select_email = mysqli_query($conexao,$query_select_email);
        $query_select_password = "SELECT password FROM usuarios";
        $select_password = mysqli_query($conexao,$query_select_password);
        while($array = mysqli_fetch_array($select_password)) {
        $logarray = $array['password'];
            if (password_verify($password, $logarray) && mysqli_num_rows($select_email) == 1) {
                echo "Login permitido";
            }
        }
    } ?>
I accept any tip related to security and to improve the code, I thank you.