我已創建此php登錄腳本。我想知道天氣是否安全,如果沒有,我該如何改進它。如何使此登錄系統更安全
PHP腳本
<?php
include_once ("ConnectToMySql.php");
session_start();
$username = $_POST['username'];
$username = mysql_real_escape_string($username);
$password = $_POST['password'];
$password = sha1($password);
$query = "SELECT password FROM users WHERE username = '$username';";
$result = mysql_query($query);
if(mysql_num_rows($result) < 1)
{
echo "This Username Is Not Registered!";
exit;
}
if(mysql_num_rows($result) == 1)
{
if ($password == $result)
{
echo "Logged In!";
}
else echo "Wrong Password!";
}
?>
感謝
谷歌搜索「php安全登錄表單」帶回了豐富的好帖子,如http://tinsology.net/2009/06/creating-a-secure-login-system-the-right-way/ – Joe 2012-02-14 11:09:44
也對空值應用服務器端驗證,以便數據庫查詢更安全 – 2012-02-14 11:18:42