-1

我有以下用于注册网站的 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 代码放在很多地方,但无济于事。

4

3 回答 3

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

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

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

但归根结底,MD5 对安全性的作用并不大。考虑bcrypt,停止使用这些mysql_*函数,并开始学习 SQL 注入攻击。

于 2012-12-07T21:43:05.610 回答
2

You're not doing anything with the return value of the functions. It should be:

$Password = md5($Password);

$RepeatPassword = md5($RepeatPassword);

于 2012-12-07T21:42:48.930 回答
-2

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

$Password = md5($Password);

$RepeatPassword= md5($RepeatPassword);

于 2013-04-29T01:35:29.993 回答