为什么$ password = password_hash($ password,PASSWORD_DEFAULT);不在数据库中存储加密密码?

时间:2017-01-08 21:34:40

标签: php mysqli

我是这个php的新手,我正在努力学习/理解它。 但现在我有问题,我无法让我的注册/登录工作...... 让我先向您展示我的register.php(不存储加密密码):

<?php
session_start();

//connect to database
$db = mysqli_connect("localhost", "XXXX", "XXXX", "XXXXX");
$mysqli->set_charset("utf8")
if(!$db)
{
    exit("Verbindungsfehler: ".mysqli_connect_error());
}

if (isset($_POST['register_btn'])) {
    $username = $_POST['username'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $password2 = $_POST['password2'];

    if($password == $password2) {
        //create user
        $password = password_hash($password, PASSWORD_DEFAULT); //hash password before storing for security purposes
        $sql = "INSERT INTO users(username, email, password) VALUES ('$username', '$email', '$password')";
        mysqli_query($db, $sql);
        session_start();
        $_SESSION['message'] = "Sie sind jetzt eingeloggt";
        $_SESSION['username'] = $username;
        header("location: reg_pos.php"); //redirect to page: Registrierung erfolgreich
    }
}
?>

一些html-form:

<form method="post" action="register.php">          
            <table>
                <tr>
                    <td>Ihr Name:</td>
                    <td><input type="text" name="username" class="textInput"></td>
                </tr>
                <tr>
                    <td>Ihre E-Mail:</td>
                    <td><input type="email" name="email" class="textInput"></td>
                </tr>
                <tr>
                    <td>Ihr Passwort:</td>
                    <td><input type="password" name="password" class="textInput"></td>
                </tr>
                <tr>
                    <td>Passwort wiederholen:</td>
                    <td><input type="password" name="password2" class="textInput"></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" name="register_btn" value="Registrieren" class="regbtn"></td>
                </tr>
            </table>
        </form>

它没有在数据库中存储散列的密码......为什么?我什么都没有到这里来?

0 个答案:

没有答案