我正在尝试散列密码并将其存储在 mySql 数据库中。使用 localhost 存储时这很好,现在我已经转移到服务器上,散列方法阻止了整个工作。如果我删除散列码,它保存得很好,但我希望散列密码。看起来很奇怪,因为相同的代码在本地运行良好,并且基于 Web 的代码可以很好地连接到 Sql。我尝试了各种不同的哈希方法,只要我尝试任何我得到的就是
“2013-10-15 22:37:07.915 UsernameAndPasswordwithphp[20249:a0b] 来自服务器的响应 =”
而不是
“2013-10-15 22:54:53.750 UsernameAndPasswordwithphp[21323:a0b] 来自服务器的响应 = 已建立连接数据库选择”
我正在运行 php 5.5.3
提前谢谢了!
这是我的代码
<?php
//session_start()
$host = "";
$user = "";
$pass = "";
$db = "";
$r = mysql_connect($host, $user, $pass);
if (!$r) {
echo "Could not connect to server\n";
trigger_error(mysql_error(), E_USER_ERROR);
} else {
echo "Connection established\n";
}
$r2 = mysql_select_db($db);
if (!$r2) {
echo "Cannot select database\n";
trigger_error(mysql_error(), E_USER_ERROR);
} else {
echo "Database selected\n";
}
$usernameFromApp = $_GET["f1"];
$nameFromApp = $_GET["f2"];
$passwordFromApp = $_GET["f3"];
$timeTarget = 0.2;
$cost = 9;
do {
$cost++;
$start = microtime(true);
password_hash($passwordFromApp, PASSWORD_BCRYPT, ["cost" => $cost]);
$end = microtime(true);
} while (($end - $start) < $timeTarget);
$hash = password_hash($passwordFromApp, PASSWORD_BCRYPT, ["cost" => $cost]);
echo "Appropriate Cost Found: " . $cost . "\n";
echo $hash."\n";
$name = $_GET["f2"];
$username = $_GET["f1"];
$password = $hash;
//$password = $_GET["f3"];
$query = "INSERT INTO user VALUES ('', '$name','$username','$password')";
mysql_query($query) or die (mysql_error("error"));
mysql_close();
?>