繁体   English   中英

PHP md5哈希无法正常工作

[英]PHP md5 hashing not working

我有以下用于注册到网站的PHP代码。 为了安全起见,我试图对密码进行哈希处理,但是每当我提交虚拟注册时,密码都不会在phpMyAdmin中进行哈希处理。 他们看起来很正常。 这是我的代码:

<?php

//get the values from the form
$Name = $_POST['name'];
$Username = $_POST['username'];
$Password = $_POST['password'];
$RepeatPassword = $_POST['repeatpassword'];

//encrypt the passwords
md5($Password);
md5($RepeatPassword);

//query the database
$query = "INSERT INTO users VALUES ('', '$Name', '$Username', '$Password')";

if (!mysql_query($query)) {

die('Error ' . mysql_error() . ' in query ' . $query);
} 

//check passwords match
if ($Password !== $RepeatPassword) {
echo "Your passwords do not match. <a href='login.php'>Return to login page</a>";

}

//check to see if fields are blank
if ($Name=="") {
echo "Name is a required field. <a href='login.php'>Return to login page</a>";
}

else if ($Username=="") {
echo "Username is a required field. <a href='login.php'>Return to login page</a>"; 
}

else if ($Password=="") {
echo "Password is a required field. <a href='login.php'>Return to login page</a>";
}

else if ($RepeatPassword=="") {
    echo "Repeat Password is a required field. <a href='login.php'>Return to login page</a>";
}

else {
    $_SESSION["message"] = "You have successfully registered! Please login using your username and password.";
    header("Location: login.php");
}
?>

我在网上阅读的所有教程都说可以按照上述方法进行。 我曾尝试将md5代码的两行放在许多地方,但无济于事。

md5($Password);
md5($RepeatPassword);

这段代码基本上什么也不做。 你要:

$Password = md5($Password);
$RepeatPassword = md5($RepeatPassword);

但是最终,MD5在安全性方面做得并不多。 考虑使用bcrypt ,停止使用mysql_*函数,并开始学习有关SQL注入攻击的知识。

您不会对函数的返回值做任何事情。 它应该是:

$Password = md5($Password);

$RepeatPassword = md5($RepeatPassword);

它不起作用,因为您没有将md5分配给变量。 做这样的事情:

$Password = md5($Password);

$RepeatPassword= md5($RepeatPassword);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM