mardi 5 mars 2019

Login form is logging in any user with any password

I am using php and ibm db2 to create simple login page. but the code is not working fine. kindly let me know where I am wrong

sharing image of code login code also

pasting code snippet below;

if (isset($_POST['login'])) {
$username = ($_POST['username']);
$password = ($_POST['password']);

if (empty($username)) {
    array_push($errors, "Username is required");
}
if (empty($password)) {
    array_push($errors, "Password is required");
}

elseif (count($errors)==0) {
    //$password = md5($password);

    $query = "SELECT * FROM people WHERE username = '$username' AND password = '$password'";
    $results = db2_exec($db, $query);

    if (db2_num_rows($results)) {

        $_SESSION['username'] = $username;
        $_SESSION['success'] = "Logged in successfully";
        //echo "<script type='text/javascript'>window.location.href = 'index.php';</script>";
        header('Refresh: 0; URL=index.php', true, 301);
    }else{
        array_push($errors, "Wrong username/password combination, Please try again.");
    }
}

}




Aucun commentaire:

Enregistrer un commentaire