Jump to content

PHP. Login form code is OK?


nitiphone2021
 Share

Recommended Posts

I created a login form for my system and I don't sure that it's enought for security to protect my website?

 include("database.php");
   session_start();
   
   if($_SERVER["REQUEST_METHOD"] == "POST") {
      // username and password sent from form 
      
      $stmt = $conn->prepare("SELECT Sale_ID FROM tb_sales WHERE Login_Name = ? AND Login_Password = ? LIMIT 1");
      $stmt->bind_param("ss", $_POST['username'], $_POST['password']);

      $stmt->execute();
      $res = $stmt->get_result(); 
     
  
      $count = mysqli_num_rows($res);
      
      if($count == 1) {
        // session_register("myusername");
         $_SESSION['login_user'] = $_POST['username'];
         echo "Login Succcess";
         //header("location: index.php");
      }else {
         echo "Your Login Name or Password is invalid";
      }
   }

 

Link to comment
Share on other sites

1. $_POST data can't be trusted, not just inside of SQL queries but also inside of $_SESSION.
2. You are not using remotely acceptable password practices. Learn about password hashing using and password_hash() and password_verify().

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.