Fout in PHP

Gestart doorEleky6 reacties36 weergaven

7 berichten · pagina 1 van 1

Eleky

Lid · Topicstarter

Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Goed, ik heb hetvolgende:

if(isset($_POST[inloggen])){
    $username = $_POST[gebruikersnaam];
    $password = $_POST[wachtwoord];
    if($username ==  || $password == ) {
        echo "U hebt niet alle velden ingevuld!";
    }
    else{
        include(config.php);
        if(!mysql_query("SELECT * FROM Leden WHERE username = $username")){
            echo "Gebruiker bestaat niet!";
        }
        else{
            $password2 = md5($password);
            if(!mysql_query("SELECT * FROM Leden WHERE username = $username AND password = $password2")){
                echo "Het wachtwoord was incorrect!";
            }
            else{
            }
        }
    }
}


Dit is voor mijn inlogsysteem.
Alleen crasht het bij de check of de username bestaat.
Maar wat doe ik daar fout?
Als ik een gebruikersnaam heb die wel bestaat, krijg ik alsnog gewoon Gebruiker bestaat niet
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
if(mysql_num_rows($sql) != 0)
0
Eleky

Lid · Topicstarter

Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
werkt niet..
En volgens mij werkt if(!) gewoon ook hoor, alleen zit er ergens een fout
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
1) !mysql_query() betekend volgens mij "Als mysql_query() niet uitgevoerd kon worden"
2) Variablen buiten de quotes halen
3) Binnen een mysql_query moet een string binnen quotes
4) Je code is gevoelig voor sql injecties

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]config.php[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]inloggen[/COLOR][COLOR= #007700]]))
{[/COLOR]
    [COLOR= #0000BB]$username[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]];[/COLOR]
    [COLOR= #0000BB]$password[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]wachtwoord[/COLOR][COLOR= #007700]];[/COLOR]
    
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$username[/COLOR][COLOR= #007700]) ||[/COLOR] [URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$password[/COLOR][COLOR= #007700]))
    {[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"U hebt niet alle velden ingevuld!"[/COLOR][COLOR= #007700];
    }[/COLOR]
    [URL="http://www.php.net/else"]else[/URL]
    [COLOR= #007700]{[/COLOR] 
        [COLOR= #0000BB]$sQuery[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT 1 FROM Leden WHERE username = "[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$username[/COLOR][COLOR= #007700]) .[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sQuery[/COLOR][COLOR= #007700]) ==[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700])
        {[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Gebruiker bestaat niet!"[/COLOR][COLOR= #007700];
        }[/COLOR]
        [URL="http://www.php.net/else"]else[/URL]
        [COLOR= #007700]{[/COLOR]
            [COLOR= #0000BB]$sQuery[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM Leden WHERE username = "[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$username[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000]" AND password = "[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/md5"]md5[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$password[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sQuery[/COLOR][COLOR= #007700]) ==[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]) 
            {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Het wachtwoord was incorrect!"[/COLOR][COLOR= #007700];
            }[/COLOR]
            [URL="http://www.php.net/else"]else[/URL]
            [COLOR= #007700]{[/COLOR]
                [COLOR= #0000BB]$sFetch[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sQuery[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]// $sFetch houd nu de gegevens van de gebruiker vast, deze kan je in een sessie of cookie laten zetten.[/COLOR]
            [COLOR= #007700]}
        }
    }
}[/COLOR]
?>
0
Eleky

Lid · Topicstarter

Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Danku,
Maar ik was inderdaad nog niet met beveiliging bezig geweestbiggrinMaar dat is ook niet heel belangrijk, aangezien het om een opdracht voor school gaat, niet voor Informatica ofzo, maar gewoon erbij.
Dus beveiliging is niet nodigbiggrin
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Eleky schreef:
Danku,
Maar ik was inderdaad nog niet met beveiliging bezig geweestbiggrinMaar dat is ook niet heel belangrijk, aangezien het om een opdracht voor school gaat, niet voor Informatica ofzo, maar gewoon erbij.
Dus beveiliging is niet nodigbiggrin
Dan nog, ik ben een persoon die veiligheid voorop stelt emo
0
Eleky

Lid · Topicstarter

Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
tja.....
Ik ben niet echt goed in beveiligen van scripts, en dan ga ik het neit uitzoeken voor een schoolopdracht waar het niet nodig isbiggrin
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren