Okay, essentially what my question is asking is if their is any major security threats using the login script below and if so what can I use to prevent any SQL injections or users logging into my service without providing correct details? I understand that I'm using an outdated version of PHP however my whole site is built on this previous version and I understand this poses risks using a outdated build.
Login Form
<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>
Form Post
<? 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" />');
}?>
Thankyou for helping me improve the security of my code and preventing any SQL injections.