v2.5.2
Giriş yap

Kodum'da SQL injection açığı bulunuyor mu?

utku5420
740 defa görüntülendi

Merhaba PHP ile yeni yeni uğraşıyorum. Login sistemi için ufak bir kod yazdım. Kodum da SQL injection için açık bulunuyor mu? Ve kodumu nasıl daha geliştirebilirim?
Şimdiden teşekkürler!

if (isset($_POST["loginAttempt"])) {

$username = htmlentities($_POST["username"]);
$password = htmlentities($_POST["password"]);
if (!empty($username) &&
    !empty($password)) {
    require "_requires/conn.php";
    $run = $conn->prepare("SELECT user_id,username,password FROM users WHERE username = ? AND status = '1'");
    $conn = null;
    $run->bindParam(1, $username, PDO::PARAM_STR);
    $run->execute();
    $user = $run->fetch();
    if ($run->rowCount()) {
        if (password_verify($password, $user["password"])) {
            $_SESSION["AUTH"] = [
                "ID" => $user["user_id"],
                "IP" => $_SERVER["REMOTE_ADDR"],
                "BIRTH" => time(),
            ];
            $_SESSION["LAST_ACTIVITY"] = time();
            header("Location: /panel/");
            exit();
        } else {
            $error_msg = "Giriş Başarısız.";
        }
    }
} else {
    $error_msg = "Giriş Başarısız.";
}

}

arco
1475 gün önce

$run->bindParam(1, $username, PDO::PARAM_STR);
sayesinde bulunmuyor hocam :) Gayet güvenli için rahat olsun