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
Torrent Trader PDO Update Beta Test
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / M-BiTsy / M-BiTsy Support

2020-04-09 23:30:06
[USER=20311]@shadows[/USER]  what do you think of this for getting current user without a global this way it can be passed around easier with the constructor
dont want to be passing globals around if i can help it, ive removed the array config and replaced with one where they defined like you suggested
to avoid having to pass $site_config around
using the cookie[pass] the token is encrypted and generated at every login
when a member visits the original cookie functions are still there so there not automatically signed in



   // set token
   if(isset($_COOKIE['pass'])) {
       DB::run("UPDATE users SET token=? WHERE id=?", [$_COOKIE['pass'], $_COOKIE['uid']]);
   }

   // replace curuser with model method
   $res = DB::run("SELECT * FROM users INNER JOIN groups ON users.class=groups.group_id WHERE token=? AND users.enabled='yes' AND users.status = 'confirmed'", [$_COOKIE['pass']]);
   $row = $res->fetch(PDO::FETCH_ASSOC);

//  $row = $this->userModel->getToken()
//  echo $_COOKIE['pass'];
//  example $2y$10$4.YE57V9O.GbaT/4NqKcEuY3j04ODZVQUp3Jzgus9uRUSMdN1TQxi
2020-04-10 03:57:37
Your completely over-complicating a simple query. Just use it as it is. All this FETCH_LAZY is lack of understanding the procedural necessities. Simply your work. Developers will thank you later.
2020-04-10 08:56:45
The issue I have at minute is I have to pass the globals around in the class controllers ($site_config i use define but that was another)
  class Home extends Controller {
 
   public function __construct(){  
   }
 
   public function index(){
       global $CURUSER;


if i remove the global $curuser in dbconn function i need to collect curuser through the user model
2020-04-11 19:27:27
managed to finally remove globals heres what i have

user model
<?php
 class User {
   private $db;

   public function __construct(){
     $this->db = new Database;
   }

   // get current user
   public function setCurrentUser(){
     $row = $this->db->run("SELECT * FROM users INNER JOIN groups ON users.class=groups.group_id WHERE token=? AND users.enabled='yes' AND users.status = 'confirmed'", [$_COOKIE['pass']])->fetch(PDO::FETCH_OBJ);

     return $row;
   }

 }


home controller
<?php
 class Home extends Controller {
   
   public function __construct(){
     $this->userModel = $this->model('User');
   }
   
   public function index(){

dbconn(true);
stdhead(T_("HOME"));

// replaces global $CURUSER;
$curuser = $this->userModel->setCurrentUser();

//check
if (file_exists("check.php") && $curuser->class == 6){


and the token is generated on login
/*
   //Get User Details And Permissions
   $res = DB::run("SELECT * FROM users INNER JOIN groups ON users.class=groups.group_id WHERE id=$_COOKIE[uid] AND users.enabled='yes' AND users.status = 'confirmed'");
   $row = $res->fetch(PDO::FETCH_ASSOC);
*/

   // set token
   if(isset($_COOKIE['pass'])) {
       DB::run("UPDATE users SET token=? WHERE id=?", [$_COOKIE['pass'], $_COOKIE['uid']]);
   }

   // replace curuser with model method
   $res = DB::run("SELECT * FROM users INNER JOIN groups ON users.class=groups.group_id WHERE token=? AND users.enabled='yes' AND users.status = 'confirmed'", [$_COOKIE['pass']]);
   $row = $res->fetch(PDO::FETCH_ASSOC);
Unknown User
2020-04-12 14:42:41
Idk mvc module is not worth it if it is not laravel or symphony.
2020-04-15 00:05:11
Has the Git repository been moved or taken offline?

[URL unfurl="true"]https://github.com/M-jay84/Torrent-Trader-2020-PDO[/url]

Does not show anything anymore.
If It Ain't Dutch, It Ain't Much!!
2020-04-15 06:27:56
I was cleaning my git and removed my old projects like v3 modded, the mvc pdo one i re-did so i could make the comments a little better and so the changes i made are clearer for anyone wanting to update their own you can go through the git for guidance.

Its now finished i was going to post it yesterday but STORRENTS2020 had already posted his, so it seemed silly posting both on same day. The project is still going  (y)
It is mvc now, i think its worth it with all the scripts ive seen of TT they all so messy, mvc makes it easy in the longer run you dont need a large package like sympthnoy or laravel to do it

Just need to clean controllers up but that doesn't effect the release it will be just small updates (adding 2 files will do one controller)
This gives me a bit of time, the weathers getting nicer here so im out more and at the same time allows members to use it and give me feedback.

Ill add it back sometime today but wont post it on the site for a few days id encourage members to try STORRENTS2020 copy if they can, even if its just to give him feed back

heres the login/logout (yes the account-login.php & account-logout.php are in the same file)
This is the one i did on the project for the controller git example

header.php (example of calling logout)
// call controller/method
echo " [<a href='/users/logout'><font color='#fff'>".T_("LOGOUT")."</font></a>] ";
     


views/user/login.php (just the html)
<form method="post" action="users/login">
 <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>

</form>
<p align="center"><a href="accountsignup"><?php echo T_("SIGNUP"); ?></a> | <a href="accountrecover"><?php echo T_("RECOVER_ACCOUNT"); ?></a></p>


User model
<?php
 class User {
   private $db;

   public function __construct(){
     $this->db = new Database;
   }
   // Get User by ID
   public function getUserByUsername($username){
     $row = $this->db->run("SELECT id, password, secret, status, enabled FROM users WHERE username =? ", [$username])->fetch();
     return $row;
   }

 }


then the controller with login/logout methods/functions
[color=rgb(250, 197, 28)]if you look at the old tt logout & login files you can see how easy it is to move the root php files to controller methods/functions[/color]
?php
class Users extends Controller
{
   // autoload model with constructor
   public function __construct()
   {
       $this->userModel = $this->model('User');
   }

   public function login()
   {
       dbconn();
       // add globals
       global $site_config, $CURUSER;

       $username = $_POST['username'] ?? false;
       $user_password = $_POST['password'] ?? false;
       $message = '';

       if ($username && $user_password) {

           $password = $user_password;
           // called model method/function
           $row = $this->userModel->getUserByUsername($username);

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

           if (!$message) {

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

       logoutcookie();

       stdhead(T_("LOGIN"));

       begin_frame(T_("LOGIN"));

       if ($site_config["MEMBERSONLY"]) {
           $message = T_("MEMBERS_ONLY");
           print("<center><b>" . $message . "</b></center>\n");
       }

       // add view
       $data = [
         //  we can add data to view 'posts' => $posts
         ];
         // load view
         $this->view('account/login', $data);

       end_frame();
       stdfoot();
   }
 
   public function logout()
   {
       dbconn();
       logoutcookie();
       header("Location: /index.php");
   }
}
Unknown User
2020-04-15 14:01:57
Some security enhancements

1. Sanitize all the $_POST field in login and register to prevent XSS.
$_POST  = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);

2. use the identical operator (===) rather than ! or empty()
if ($message === '')
{
   ....
}

3. Use destructor to close active sql connection when execution is completed (this should be automatically done by PHP, but it won't work if database connection is persistent)

4. I'm using a CSRF token (generated via session) for login and register, so no automated requests can be done https://wiki.php.net/rfc/automatic_csrf_protection
2020-04-30 18:55:49
Bit of a chat with m-jay, I got this far last night in handling SHA1 => BCrypt rehashing however, as silly as it is.. I can not get the user ID or cookie UID? Over 10K members locked out until this is working. Once we turn back on the SQL fetch, it refuses to execute and complains all about the query with little to go off of.

What it does: Checks if user password needs to be rehashed, if so it inserts to "page", to not effect real user data. I'm quite stuck.


function userlogin() {
   $ip = getip();
   // If there's no IP a script is being ran from CLI. Any checks here will fail, skip all.
   if ($ip == '') return;

   GLOBAL $CURUSER;
   unset($GLOBALS["CURUSER"]);

   /* DISABLED FOR TESTING THIS VERSION - APRIL 16
   //Check IP bans
   if (is_ipv6($ip))
       $nip = ip2long6($ip);
   else
       $nip = ip2long($ip);
   */
 
   $res = DB::run('SELECT * FROM bans WHERE true');
   while ($row = $res->fetch(PDO::FETCH_ASSOC)){
       $banned = false;
       if (is_ipv6($row["first"]) && is_ipv6($row["last"]) && is_ipv6($ip)) {
           $row["first"] = ip2long6($row["first"]);
           $row["last"] = ip2long6($row["last"]);
           $banned = bccomp($row["first"], $nip) != -1 && bccomp($row["last"], $nip) != -1;
       } else {
           $row["first"] = ip2long($row["first"]);
           $row["last"] = ip2long($row["last"]);
           $banned = $nip >= $row["first"] && $nip <= $row["last"];
       }
       if ($banned) {
           header("HTTP/1.0 403 Forbidden");
// todo        echo "<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Forbidden</title></head><body><h1>Forbidden</h1>Unauthorized IP address.<br />";
       //    "Reason for banning: $row[comment]</body></html>";
       //    die;
       }
   }
 
   /*
   //Check The Cookie and get CURUSER details  
   if (strlen($_COOKIE["pass"]) != 60 || !is_numeric($_COOKIE["uid"])) {  
       //logoutcookie();  
       return;  
   }  
   //Get User Details And Permissions
   $res = DB::run("SELECT * FROM users INNER JOIN groups ON users.class=groups.group_id WHERE id=$_COOKIE[uid] AND users.enabled='yes' AND users.status = 'confirmed'");
   $row = $res->fetch(PDO::FETCH_ASSOC);
   $hash = $row["id"].$row["secret"].$row["password"].$ip.$row["secret"];
   if (!$row || !password_verify($hash,$_COOKIE["pass"])){
       logoutcookie();
       return;
   }
   */
 
   $id = (int) 6; // we need our user ID!! Not 6 (dummy account for testing)

   // Get User Details And Permissions & Check if password is BCRYPT => Update
   if (strlen($_COOKIE["pass"]) != 60 || !is_numeric($_COOKIE["uid"])) {
   //logoutcookie();
   $hash = $row["id"] . $row["secret"] . $row["password"] . $ip . $row["secret"];
   if (password_needs_rehash($hash, PASSWORD_BCRYPT, array(
       "cost" => 7
   ))) {
       $hash = password_hash($password, PASSWORD_BCRYPT, array(
           "cost" => 7
       ));
       //echo $hash;
       //$id = $row['id'];

       // Save new hash (update Page column for safety/live site)
       $stmt = DB::run("UPDATE users SET page=? WHERE id=?", [$hash, $id]);
   }
       return;
   }

   $where = where ($_SERVER["SCRIPT_FILENAME"], $row["id"], 0);
 
   $id = $row['id'];
   $stmt = DB::run("UPDATE users SET last_access=?,ip=?,page=? WHERE id=?", [get_date_time(),$ip,$where,$id]);
   $GLOBALS["CURUSER"] = $row;
   unset($row);
}


It could be highly insecure, and while the goal was to generate new hash and insert to password, set cookies and login, works but ID not retrieved by login. Please advice!

This is userlogin() in /helpers/functions.php
Unknown User
2020-04-30 19:20:31
Just do a double rehashing in account login.

Didn't test it, but should work as intended as it worked in my head :D

if (password_verify($_POST['password'], $row["password")) 
{
/* Add login cookie here
* User has the new hashing method which is working.
*/
logincookie();
}
else
{
if ($row["password"]  === $_POST['password'])
{
    // We are updating the old md5 password or whatever it is.
     $newPassword = password_hash($_POST['password'], PASSWORD_BCRYPT);
     $stmt = DB::run("UPDATE users SET password = ? WHERE id= ?", [$newPassword, $id]);
     logincookie($row["id"], $newPassword, $row["secret"]);
}
else
{
// Password is not correct in either md5 or bcrypt format
logoutcookie();
}
}
2020-04-30 19:30:45
Thats funny, shadows.. I literally just realized that too and went to work at it, working! The work is now in /controllers/Accountlogin.php

We were not far off! lol


public function index()
   {
       dbconn();
       // add globals
       global $site_config, $CURUSER;

       $username = $_POST['username'] ?? false;
       $user_password = $_POST['password'] ?? false;
       $message = '';

       if ($username && $user_password) { // form not empty, continue

           $password = $user_password;
           // called model method/function
           $row = $this->userModel->getUserByUsername($username);
         
   if (password_needs_rehash($row["password"], PASSWORD_BCRYPT, array(
       "cost" => 7
   ))) {
       $hash = password_hash($row["page"], PASSWORD_BCRYPT, array(
           "cost" => 7
       ));

       // Update new hash
       $stmt = DB::run("UPDATE users SET page=? WHERE id=?", [$hash, $row['id']]);
   }
2020-05-16 11:52:41
Hello
I install on account-details and on the torrent uploader when I choose another page it returns me on detail and does not take my choice of page

Thank you for your help.

[ATTACH type="full" alt="Capt3ure.PNG"]5537[/ATTACH]


// start id3
echo "<div id=id3 style=display:none;>";
   #begin_frame(T_("UPLOADED_TORRENTS"));
   //page numbers
   $page = (int) $_GET["page"];
   $perpage = 25;
   $where = "";
   if ($CURUSER['control_panel'] != "yes")
   $where = "AND anon='no'";
   $res = SQL_Query_exec("SELECT COUNT(*) FROM torrents WHERE owner='$id' $where");
   $row = mysqli_fetch_array($res);
   $count = $row[0];
   unset($where);

   $orderby = "ORDER BY id DESC";

   //get sql info
   if ($count) {
       list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, "account-details.php?id=$id&amp;");
       $query = "SELECT torrents.id, torrents.category, torrents.leechers, torrents.nfo, torrents.tube, torrents.tube2, torrents.sticky, torrents.seeders, torrents.name, torrents.times_completed, torrents.size, torrents.added, torrents.comments, torrents.numfiles, torrents.filename, torrents.owner, torrents.external, torrents.freeleech, categories.name AS cat_name, categories.parent_cat AS cat_parent, categories.image AS cat_pic, users.username, users.privacy, torrents.anon, torrents.uplreq, IF(torrents.numratings < 2, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating, torrents.announce FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id WHERE owner = $id $orderby $limit";
       $res = SQL_Query_exec($query);
   }else{
       unset($res);
   }

   if ($count) {
       print($pagertop);
       torrenttable($res);
       print($pagerbottom);
   }else {
       print("<b>".T_("UPLOADED_TORRENTS_ERROR")."</b><br />");
   }

   #end_frame();
}
echo "</div>";
// end id3
Capt3ure.PNG
Capt3ure.PNG

2020-05-16 21:28:30
Memcached? Pager not working as results are dynamic.
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: 1
  • Members: 0
  • Guests online: 1
  • Comments: 3
  • Messages: 1,728