如何把md5解密放在这上面

时间:2017-11-30 06:01:46

标签: php mysqli

$ email = strip_tags($ _ POST [' email']);     $ password = strip_tags($ _ POST ['密码']);

$email = $DBcon->mysqli_real_escape_string($email);
$password = $DBcon->mysqli_real_escape_string($password);
$password= md5($password);
$query = $DBcon->query("SELECT id, email, password FROM food_user WHERE email='$email' and password='$password");
$row=$query->fetch_array();

$count = $query->num_rows; // if email/password are correct returns must be 1 row

if (password_verify($password, $row['password']) && $count==1) {
    $_SESSION['userSession'] = $row['id'];
    header("Location: cookiecups.php");
    $msg = "<div class='alert alert-danger'>
                <span class='glyphicon glyphicon-info-sign'></span> &nbsp; Invalid Username or Password !
            </div>";
 } else {
    $msg = "<div class='alert alert-danger'>
                <span class='glyphicon glyphicon-info-sign'></span> &nbsp; Invalid Username or Password !
            </div>";
}
$DBcon->close();

1 个答案:

答案 0 :(得分:1)

MD5不能像哈希算法那样“解密”https://en.wikipedia.org/wiki/MD5

要加密/解密字符串,您应该使用AES https://en.wikipedia.org/wiki/Advanced_Encryption_Standard

之类的内容

您可能意味着“如何比较”,但在您的用户案例中,使用md5函数散列用户密码是完全错误的(也不安全);你应该依赖bcrypt(https://en.wikipedia.org/wiki/Bcrypt)或使用像Akintunde在评论中写的密码_hash()(http://php.net/manual/en/function.password-hash.php)函数。

希望它有所帮助;)