ds342222222 2018-07-04 09:18
浏览 18

密码不与MySQLi哈希

I'm currently making a registration form, everything seems to work fine except for the password part. When the user register, the password should be hashed but I still see a normal string in phpmyadmin. I would like to make it when a user input his password, it should be hashed in the database.

Here is my code:

public function reg_user($gender, $username, $email, $password, $firstname, $lastname, $birthday, $city) {
            $sql = "SELECT * FROM users WHERE username='$username' OR email='$email'";  
            password_hash($password, PASSWORD_DEFAULT);
            password_verify($password,$row['password']);
            $check =  $this->db->query($sql);
            $count_row = $check->num_rows;
            if ($count_row == 0) {
                $sql1 = "INSERT INTO users (gender, username, email, password, firstname, lastname, birthday, city) VALUES ('$gender', '$username', '$email', '$password', '$firstname', '$lastname', '$birthday', '$city')";
                $result = mysqli_prepare($this->db,$sql1) or die(mysqli_connect_errno() . " - ERREUR: Les données ne peuvent pas être insérés");
                $password = md5($password, PASSWORD_DEFAULT);
                $result->execute();
            } else {
                return false;
            }
        }

        include_once 'class.user.php';
        $user = new User();
        password_verify($password,$row['password']);
        password_hash($password, PASSWORD_DEFAULT);
        $password = password_hash($password, PASSWORD_DEFAULT);
        if (isset($_POST['submit'])) {
            extract($_POST);
            $register = $user->reg_user($_POST['gender'], $_POST['username'], $_POST['email'], $_POST['password'], $_POST['firstname'], $_POST['lastname'], $_POST['birthday'], $_POST['city']);
            if ($register) {
                echo "<span class=\"waters\">Inscription confirmée</span>";
                password_verify($password,$row['password']);
                password_hash($password, PASSWORD_DEFAULT);
            } else {
                echo "<span class=\"waters\">Inscription confirmée</span>";
                password_verify($password,$row['password']);
                password_hash($password, PASSWORD_DEFAULT);
            }
        }

Thanks for reading.

  • 写回答

1条回答 默认 最新

  • dqouryz3595 2018-07-04 09:23
    关注

    Change the order of lines: you first generate the SQL query, and afterwards call a hash method for the given password.

    Additionally, keep in mind that md5 is not a secure hash function any more

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算