Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
Updated login for security
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / Torrent Trader / v3 Support

2023-03-01 04:40:12
This is an updated copy of the account-login.php file from github of TTv3. I cant test this exactly just now, but I updated my own copy, which is more modified than this, so I tried to bring over some key items to see if this is more secure than the old one. This should be prepared statements on the username and password. I think at the very least the prepared login is a big step in a better direction.  Let me know if you see any problems
<?php
// Updated login for sql injection security March 2023
require_once("backend/functions.php");
dbconn();
session_start();

if (!empty($_REQUEST["returnto"])) {
   if (!isset($_GET["nowarn"])) {
       $nowarn = T_("MEMBERS_ONLY");
   }
}

if (isset($_POST["username"]) && isset($_POST["password"])) {
   $password = passhash($_POST["password"]);

   if (!empty($_POST["username"]) && !empty($_POST["password"])) {
       $stmt = $GLOBALS["DBconnector"]->prepare("SELECT id, password, secret, status, enabled FROM users WHERE username = ?");
       $stmt->bind_param("s", $_POST["username"]);
       $stmt->execute();
       $res = $stmt->get_result();
       $row = $res->fetch_assoc();

       if (!$row || ($_POST["password"] == $row["password"])) {
           $message = T_("LOGIN_INCORRECT");
       } elseif ($row["status"] == "pending") {
           $message = T_("ACCOUNT_PENDING");
       } elseif ($row["enabled"] == "no") {
           $message = T_("ACCOUNT_DISABLED");
       }
   } else {
       $message = T_("NO_EMPTY_FIELDS");
   }

   if (!$message) {
       logincookie($row["id"], $row["password"], $row["secret"]);
       if (!empty($_POST["returnto"])) {
           header("Refresh: 0; url=" . $_POST["returnto"]);
           die();
       } else {
           header("Refresh: 0; url=index.php");
           die();
       }
   } else {
       show_error_msg(T_("ACCESS_DENIED"), $message, 1);
   }
}

logoutcookie();

stdhead(T_("LOGIN"));

if (isset($nowarn)) {
   show_error_msg(T_("ERROR"), $nowarn, 0);
}


begin_frame(T_("LOGIN"));
?>

<form method="post" action="account-login.php">
   <table border="0" cellpadding="3" align="center">
       <tr>
           <td align="center">
               <b><?php echo T_("USERNAME"); ?>:</b>
               <input type="text" size="40" name="username" />
           </td>
       </tr>
       <tr>
           <td align="center">
               <b><?php echo T_("PASSWORD"); ?>:</b>
               <input type="password" size="40" name="password" />
           </td>
       </tr>
       <tr>
           <td colspan="2" align="center">
               <input type="submit" value="<?php echo T_("LOGIN"); ?>" />
               <br />
               <br />
               <i><?php echo T_("COOKIES");?></i>
           </td>
       </tr>
   </table>

   <?php
   if (!empty($_REQUEST["returnto"])) {
       ?>
       <input type="hidden" name="returnto" value="<?php echo cleanstr($_REQUEST["returnto"]); ?>" />
       <?php
   }
   ?>

</form>

<p align="center">
   <a href="account-signup.php"><?php echo T_("SIGNUP"); ?></a> |
   <a href="account-recover.php"><?php echo T_("RECOVER_ACCOUNT"); ?></a>
</p>

<?php
end_frame();
stdfoot();
?>

TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Last edited by MicroMonkey on 2023-03-04 09:14:30
2023-03-01 15:41:34
You need to use isset in your code. You must check these global variables, or arrays first before working with it.

You will surely see many warnings.
2023-03-01 20:45:09
Thanks for the suggestions. Are you meaning using isset on $GLOBALS["DBconnector"] ? I havent gotten any errors or warning on mine, but its a bit different than this one. this is the stock login page that comes with TTv3. That is defined in the functions file and it is the entire sql connection for the whole script. like this
    $GLOBALS["DBconnector"] = new mysqli($mysql_host, $mysql_user, $mysql_pass, $mysql_db);    // Check connection
   if ($GLOBALS["DBconnector"]->connect_error) {
      die("Connection failed: " . $GLOBALS["DBconnector"]->connect_error);
}

TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
2023-03-02 01:36:54
No that is just an array key pointing to a mysql instance object. That’s already true if module enabled. The connection string defines the rest.

For example,

Always always.. start all things you call for $_REQUEST, $_POST, $_GET with an initialized state check - isset

Just start writing isset($_GET[‘whatever’]) and depending on what you expect..

ALWAYS: isset($_GET[‘key’])
INT: && intval($_GET[‘key’]) > 0
STRING: && strlen($_GET[‘key’]) > 0

Use this same approach when dealing with anything in a closed scope

If (cond) { … } (we check isset here)

Better to pre-define your variables before scope

$var = ‘’;
If (true) {
  $var = ‘hello’
}

Otherwise you have to:

// no warnings, no exceptions
If (isset($var)) {
  // do
}


PHP has a consistent set of is_*<T>()

T = Type
(&var) = wrapper

is_string, is_int, is_object, is_null, etc. it’s a excellent set of conditionals that I always maintain as routine on anything I do. It’s never failed.
2023-03-02 02:20:44
thanks buddy, I appreciate the info.  😊
TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
2023-03-03 19:55:31
first post updated. Lemme know if it can be improved
TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 2
  • Members: 0
  • Guests online: 2
  • Comments: 3
  • Messages: 1,728