1

我有一个固定的用户名密码和一个可变文本。

这是第一种方法,但不安全

<form action="http://site.com/foo.php" method="post">
  <input type="hidden" name="username" value="user123" />
  <input type="hidden" name="password" value="pass123" />
<input type="text" name="text" />
<input type="submit" />

</form> 

这是第二种方法请完成此:

索引.html

<form action="foo.php" method="post">
<input type="text" name="text" />
<input type="submit" />
</form> 

foo.php

$username = "user123";
$password = "pass123";

$text = $_POST["text"];

$url  = "http://site.com/foo.php?text=".$text."&password=".$password."&username=".$username;

如何安全地发布$url?(没有 HTTPS)

4

2 回答 2

2

没有 HTTPS 就没有安全。

因为当您发送密码时,即使您对其进行了加密,网络中继节点也将获得访问权限,并且可以以这种方式使用它。

您只能使用 MD5 来防止密码观察,但它仍然可以访问。

但是在本身是加密的HTTPS中,密码不能被破解,因为有一个只有客户端和服务器知道的公钥和私钥。

也许您可以通过 HTTPS 进行登录。无需购买证书。您可以轻松地自己发布一个并将其设置在您的主机上。

对重要业务使用 HTTPS。

于 2012-07-23T06:55:06.760 回答
1

更新:

如果没有 HTTPS,您将无法安全登录。
这是非常不安全的,并且不会阻止人们在截获哈希时登录。
只需使用 HTTPS。


使用MD5 功能

例如

$url = "http://example.com/foo.php?text=".$text."&password=".md5($password)."&username=".$username;

然后在接收站点 ( http://example.com/foo.php?...) 上,使用实际密码的哈希 (MD5) 检查收到的密码。

例子:

发送文件:

$username = "user123";
$password = "pass123";

$text = $_POST["text"];

$url = "http://example.com/foo.php";
$data = "text=".$text."&password=".md5($password)."&username=".$username;

$handle = curl_init($url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($handle);
curl_close($handle);
if($result) {
    // Success
} else {
    // Failed
}

接收文件:

$username = $_POST["username"];
$password = $_POST["password"];

// Insert code here to escape the username with mysqli_real_escape_string,
// then retrieve data from database with MySQLi.

if($password == md5($db_password)) {
    // Correct password
} else {
    echo 'Incorrect password.';
}
unset($username, $password, $db_password); // For security, remove variables from memory
于 2012-07-23T06:54:15.407 回答