私の質問は基本的に、以下のログインスクリプトを使用してセキュリティ上の大きな脅威があるかどうか、もしあれば、SQLインジェクションやユーザーが正しい情報を入力せずにログインするのを防ぐために何ができるのですか?私はPHPの古いバージョンを使用していますが、私のサイト全体がこの以前のバージョンで構築されていることを理解しています。私は私のコードのセキュリティを向上させる手助けし、任意のSQLインジェクションを防ぐためのこのログインスクリプトは安全ですか?
ログインフォーム
<form method="post" action="login.php?login=login">
<input type='text' placeholder="username" class='form-control' name='username' required autofocus/>
<input type='password' placeholder="password" class='form-control' name='password' required/>
<input class='btn btn-default btn-block' type='submit' value='Login' class='submit' />
</form>
フォームポスト
<? if($login==login)
{
$username = clean($_POST[username]);
$password = md5($_POST[password]);
$date = date("Y-m-d");
$time = date("H:i:s");
$sql = mysql_query("select * from users where username = '$username' AND password = '$password'");
$check = mysql_num_rows($sql);
if($check!=1)
{
echo 'Incorrect username or password.';
echo('<meta http-equiv="refresh" content="3;url=/login" />');
$success = "Failed";
if($content[loginlog]==1)
$sqllog = mysql_query("insert into usr_logs(user, ip, time, date, success) values('$username', '$ip', '$time', '$date', '$success')");
}
else
{
$user = mysql_fetch_array($sql);
$_SESSION[usr_name] = $user[username];
$_SESSION[usr_level] = $user[level];
$_SESSION[usr_ip] = $ip;
$success = "Success";
echo('<meta http-equiv="refresh" content="1;url=/home" />');
if($content[loginlog]==1)
$sqllog = mysql_query("insert into usr_logs(user, ip, time, date, success) values('$username', '$ip', '$time', '$date', '$success')");
}
}
if($login==logout)
{
session_unset();
session_destroy();
echo 'logged out';
echo('<meta http-equiv="refresh" content="3;url=/login" />');
}?>
ありがとう。
作業コードの質に関する質問は、通常[codereview](http://codereview.stackexchange.com/help/on-topic)に属しているので、この質問をオフトピックとして閉じるよう投票しています – Quentin
ありますこのコードに関する多くの恐ろしいことと、 'clean'関数(実際にあなたが主に尋ねているものです!)が完全に欠けています。 – Quentin
ここで/ '何が' clean() 'ですか? – jDo