How to encrypt the password in a new user's registry and how do you recognize it in that user's login? [duplicate]

0

this is the code that processes the registration

    <?php
    include_once("conexao.php");

    $nome = $_POST['nome'];
    $celular = $_POST['celular'];
    $email = $_POST['email'];
    $senha = $_POST['senha'];

    $sql = "INSERT INTO usuarios (nome,celular,email,senha) VALUES ('$nome','$celular','$email','$senha')";

    $salvar = mysqli_query($conexao,$sql);

    $linhas = mysqli_affected_rows($conexao);

    mysqli_close($conexao); ?>

<!DOCTYPE HTML>

<html lang="pt-br">

    <head>
        <title>Loja - Cadastro</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0" />
        <meta name="theme-color" content="#FF0000">
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="Cache-Control" content="no-store" />
        <link rel="icon" href="../imagens/favicon.png" type="image/png" />
        <link href="../css/style.css" type="text/css" rel="stylesheet" media="screen,projection" />
        <link href="../css/materialize.css" type="text/css" rel="stylesheet" media="screen,projection" />
        <link href="../css/animate.min.css" type="text/css" rel="stylesheet" media="all">
    </head>
<body>
    <?php
        include("navbarforms.php");
    ?>

    <div class="container-fluid">

    <?php
        if($linhas == 1){
        echo "<h4>Cadastro efetuado com sucesso!</h4>";
        header("Location: ../entrar.php");
        } else {
        echo "<h5 class='red-text'>Usuário <strong>$email</strong> já existente no sistema</h5><br><p class='text-blue mdfont'>Redirecionando para a pagina de cadastro...</p>";
        header("refresh: 5; url=../cadastrar.php");
        }
    ?>

    </div>
</body>

</html>

and this is the code that processes the login

    <?php
session_start();
include("conexao.php");

if (empty($_POST['email']) || empty($_POST['senha'])) {
    header("Location: ../entrar.php;");
    exit();
}

$email = mysqli_real_escape_string($conexao, $_POST['email']);
$senha = mysqli_real_escape_string($conexao, $_POST['senha']);

$query = "SELECT email, senha FROM usuarios WHERE email = '$email' AND senha = '$senha'";

$result = mysqli_query($conexao, $query);

$row = mysqli_num_rows($result);

if ($row == 1) {
    $_SESSION['email'] = $email;
    header("location: ../index.php");
    exit();
} else {
    $_SESSION['nao_autenticado'] = true;
    header("location: ../entrar.php");
    exit();
}

?>

I would like to know how to send the encrypted password and then log in with the password entered in the registry.

    
asked by anonymous 30.11.2018 / 21:59

1 answer

-1

Take the field and use the encryption you used to send it to SELECT ex in the registry you used md5 in $ _POST ['password']; thus getting md5 ($ _ POST ['password']); at the time of login you do the same thing, so when you check the encrypted password, you will be sending the same password as the database if the user is typed correctly

    
01.12.2018 / 00:14