phpBB API – Accessing Database and Performing Sql Queries

phpBB Logo

In my two previous posts, phpBB API – Logging In And Logging Out a User and phpBB API – Auto Login a User Without a Password, I used phpBB API to perform some API functionalities such as logging in a user without a password and logging out a user.

In this post, I will use the phpBB API to perform some SQL queries on the phpBB database to change the user’s password and verify a user.

Changing a User’s Password

<?php
define(‘IN_PHPBB’, true);//Must be defined
$phpbb_root_path = ‘../phpBB3/’;//your forum directory location
$phpEx = substr(strrchr(__FILE__, ‘.’), 1);
require_once($phpbb_root_path . ‘common.’ . $phpEx);

function phpbbChangePassword($username, $newPassword)
{
global $phpbb_root_path, $phpEx, $user, $db,$table_prefix;
$newPassword = phpbb_hash($newPassword);

$sql = “UPDATE `” . $table_prefix . “users` SET user_password = ‘” . $password . “‘ WHERE username = ‘” . $username . “‘”;
$db->sql_query($sql);
$stmt->close();
}

//Changing Password for user “Test”
$username = “Test”;
$newPassword = “myNewPassword”;
phpbbChangePassword($username, $newPassword);

?>

 

Changing user’s status to verified

<?php
define(‘IN_PHPBB’, true);//Must be defined
$phpbb_root_path = ‘../phpBB3/’;//your forum directory location
$phpEx = substr(strrchr(__FILE__, ‘.’), 1);
require_once($phpbb_root_path . ‘common.’ . $phpEx);


function phpbbVerifyUser($username)
{
global $phpbb_root_path, $phpEx, $user, $db, $table_prefix;
$userType = USER_NORMAL;
$sql = “UPDATE `” . $table_prefix . “users` SET user_type = ‘” . $userType . “‘ WHERE username = ‘” . $username . “‘”;
$db->sql_query($sql);
}

//Verifying User “Test”
$username = “Test”;
phpbbVerifyUser($username);

?>

Any questions, please let me know!

Leave a Reply

Your email address will not be published. Required fields are marked *