Hello There, Guest!
View New Posts  |  View Today's Posts
[Guide] Logging into phpBB externally

  • 0 Vote(s) - 0 Average


09-23-2012, 12:48 PM #1
Epixors
(づ。◕‿‿◕。)づ・。*。✧・゜゜・。
*****
TLF Coders
Posts: 420 Threads:58 Joined: Aug 2012 Reputation: 6

[Guide] Logging into phpBB externally
Well guys, it's been a while since I've been here, sorry for that, so I thought it'd contribute this small script I wrote.

So today I had this small project and I had to login using the account I already made of a forum, so I'll explain what I did :)
It took me some grinding through the phpBB3 code but I found what I had to do.

The file functions.php in your includes directory of phpBB contains a function to hash the password, each hash is unique, but what it also contains is a function called phpbb_check_hash. We will be using this function!

Now the thing is, where I think a lot of people got stuck, is at the very top of the functions.php file. Go to it in your phpBB folder (includes/functions.php), you'll see something like:

[code=php]if(!define('IN_PHPBB')){ exit;}[/code]

Basically what it does, is preventing this file being called from outside of phpBB, so what to do? Remove it! Either just delete it, or comment it out.
Well then, time to get started :)

First of, we'll add the functions.php file, secondly we'll create a connection to the database. We'll also set our login credentials. And of course we need to start with the session_start function.

[code=php]<?php

session_start(); 
require_once "forum/includes/functions.php";
$conn = new mysqli("127.0.0.1","user","password","forumdatabase");
$user = "Epixors";
$pass = "password";

?>[/code]

Now that that is setup, it's time to do the login, don't you say :)

What we need to use for the login, is the username_clean column, and then select user_password. Secondly we see if it's 1 row that's returned and compare the password, and set the session or not based on that.

[code=php]$fetch = $conn->query("SELECT user_password FROM phpbb_users WHERE username_clean = '".strtolower($user)."'");
if($fetch->num_rows == 1){
 $result = $result->fetch_assoc();
 if(phpbb_check_hash($pass,$result['user_password'])){
  $_SESSION['login'] = $user;
 }
}[/code]

Your final code should look like this:

[code=php]<?php

session_start(); 
require_once "forum/includes/functions.php";
$conn = new mysqli("127.0.0.1","user","password","forumdatabase");
$user = "Epixors";
$pass = "password";

$fetch = $conn->query("SELECT user_password FROM phpbb_users WHERE username_clean = '".strtolower($user)."'");
if($fetch->num_rows == 1){
 $result = $result->fetch_assoc();
 if(phpbb_check_hash($pass,$result['user_password'])){
  $_SESSION['login'] = $user;
 }
}

?>[/code]

Not much more to it, this is how I implemented it:

[code=php]   public function ForumLogin($USERNAME,$PASSWORD){
    require_once "../includes/functions.php";
    require_once "class.database.php";
    
    $Connection = array("Host" => "127.0.0.1","User" => "user","Pass" => "", "Database" => "forum");
    $Database = new Database($Connection);
    
    $Userdata = $Database->ConstructDataArray(array('user_password'),"phpbb_users","WHERE username_clean='".strtolower($USERNAME)."'");
    
    if($Userdata[0]['user_password'] != ""){
     if(phpbb_check_hash($PASSWORD,$Userdata[0]['user_password'])){
      $this->SetData("Loggedin",true);
      $this->SetData("Username",$USERNAME);
      return true;
     } else{
      return false;
     }
    } else {
     return false;
    }
    
   }[/code]

Few side-notes:
- Perhaps you'll run into an error because of a typo of mine, if so, please notify me about it :)
- Your table doesn't have to be phpbb_users, phpbb_ is the standard prefix.
This post was last modified: 09-23-2012, 12:49 PM by Epixors.

09-23-2012, 06:43 PM #2
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

RE: [Guide] Logging into phpBB externally
PhpBB was one of the first forum softwares that i've used, until I discovered others like MyBB and started working with IPB and vBulletin, among others like XenForo, etc... PhpBB2 is highlight exploitable because of it's sessions, PhpBB3 isn't bad, but still not entirely secure, so that's why I abandoned it. This is interesting though. I've never seen a login method using PHP before externally. It would actually be very cool if you wanted to integrate this with another external login. For sites that use both profiles, and/or some kind of CMS with a user database, so that the user could login to either the forum or their 'other' profile and login to both at the same time.

cheers


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲

09-25-2012, 11:21 PM #3
Epixors
(づ。◕‿‿◕。)づ・。*。✧・゜゜・。
*****
TLF Coders
Posts: 420 Threads:58 Joined: Aug 2012 Reputation: 6

RE: [Guide] Logging into phpBB externally
Yeah, I used it for something like that.

09-26-2012, 09:34 AM #4
KoBE
¯\_(ツ)_/¯
******
Global Moderators
Posts: 4,862 Threads:494 Joined: Jun 2011 Reputation: 67

RE: [Guide] Logging into phpBB externally
Although I probably won't install PhpBB to test this, it looks nice! If I ever decided to use PhpBB for some reason, this thread will be nice to look back on.

09-26-2012, 09:55 AM #5
Epixors
(づ。◕‿‿◕。)づ・。*。✧・゜゜・。
*****
TLF Coders
Posts: 420 Threads:58 Joined: Aug 2012 Reputation: 6

RE: [Guide] Logging into phpBB externally
I am writing some forum integration project, so I‘ll probably write for MyBB, IPB, VBulletin and perhaps some others. Currently did Latest Threads, listing posts from specific section for blog and user profiles.

08-28-2014, 10:22 AM #6
epullay
Junior Member
**
Posts: 1 Threads:0 Joined: Aug 2014 Reputation: 0

RE: [Guide] Logging into phpBB externally
Hello.

Is there any way to use this code in visual basic? I'm kinda new to coding, and I don't quite get what I should do xP. The idea is that the username field is called as "TextBox1", and password "TextBox2". And when you hit the "Accept" button, the code runs. Like some sort of application to log-in into my forum
This post was last modified: 08-28-2014, 10:34 AM by epullay.

08-28-2014, 05:23 PM #7
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

RE: [Guide] Logging into phpBB externally
They do not have to be "TextBox1" and "TextBox2", those control names are pre-defined by the IDE to make life easier for you (in regards to not having to create them on your own). You can change those to be a little more self documenting if you wish. This is PHP though, so you cannot use this to write the VB.NET code, however the principle is the same aside from what happens behind the syntax...

If you look around, there is a VB.NET version in the .NET forum to doing this in VB.NET. If you want VB.NET information, this is the wrong section to be looking in.

cheers


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲




Forum Jump:


Possibly Related Threads...
Thread Author Replies Views Last Post
  Web Dev Guide/TuTs Requests Epixors 6 3,198 01-09-2013, 10:03 AM
Last Post: Adriana
  Simple MyBB Plugin guide [Unfinished] Jung3o 3 7,111 11-09-2012, 04:49 PM
Last Post: Jung3o
  How To Install MyBB | MyBB Installation Guide BreShiE 6 5,014 03-04-2012, 06:22 PM
Last Post: BreShiE
  Your Guide to Nulling MyBB Themes Poseidon 7 4,330 11-22-2011, 08:56 AM
Last Post: KoBE


Users browsing this thread: 1 Guest(s)