php - Login Script does not function -


I am having a minor problem with this login mechanism. This does not login to the user on most conditions if the user is newly registered So it works fine but then all other usernames are useless. The login.php page is as follows:

    

This is the script I use to see if the user is logged in or not. I paste it on all my pages.

  & lt ;? Php $ username = $ _COOKIE ['username']; if ($ username == "") {echo '& lt; Form name = "login" action = "login.php" method = "post" & gt; & Lt; Label & gt; Login & lt; / Labels & gt; & Lt; Label = "username" & gt; Username: & lt; Input type = "text" name = "username" & gt; & Lt; / Label & gt; & Lt; Label = "password" & gt; Password: & lt; Input type = "password" name = "password" & gt; & Lt; / Label & gt; & Lt; Input type = "submit" & gt; & Lt; / Form & gt; '; } Else {echo '& lt; Form action = "logout.php" & gt; Logged in as: '. $ _COOKIE ["username"] '' '& Lt; Input type = "submit" value = "logout" & gt; & Lt; / form & gt; ' ; }? & Gt;   

The problem I am facing is to echo out

  $ line ['username'];; Echo ['password'] per line;   

displays the user name and password of the line but this user does not log in.

Database structure is:

1 ID tinyint (4) 2 name short text 3 email short text 4 contact bine (20) 5 city tinyx 6 user name varchar (16) 7 password varchar (16) 8 ISDMNT tint (1)

You might want to say this

  SELECT `username ', password to the customer   

to say

  select username,' password 'from customer WHERE User name =?   

Or else it will give you to all the users in the database ... This is the reason why your form is giving you problems ... because it is checking the user first in the database. .


The following is how I will change my code ...

Change it:

  $ Result = Mysqli_query ($ con, 'Select Username', 'Password From Customer'); While ($ line = mysqli_fetch_array ($ result)) {if ($ line ['username'] === $ user name & amp; $ line ['password'] === $ password) {$ _SESSION ['user Name '] = "$ username"; Setkey ('username', $ line ['user name']); Header ("Location: http: //localhost/loggedin.php"); } And {header ("location: http: //localhost/index.html"); }   

at:

  $ query = 'Select' user name, `password` from the customer where the user name =? '; If ($ stmt = $ mysqli- & gt; Ready ($ query)) {$ stmt- & gt; Bond_param ('s', $ username); $ Stmt- & gt; Executed (); $ Stmt-> Tie-break ($ ​​get_username, $ get_password); $ Stmt- & gt; Bring (); $ Stmt- & gt; Free_result (); $ Stmt- & gt; near (); } If ($ get_username === $ user name & amp; $ get_password === $ password) {$ _SESSION ['username'] = "$ username"; Setkey ('username', $ line ['user name']); Header ("Location: http: //localhost/loggedin.php"); Go out(); } Other {header ("location: http: //localhost/index.html"); Go out(); }   

The way you are handling the password in the database is a big flaw ... they should not be a raw password ... please have them with salt, haveh and Maybe even a black pepper

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -