MyBB Community Forums

Full Version: Adding a User From Another Application
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi ... I have another application that folks have a username/password to access.  I want to be able to add them to myBB using those same credentials through the other applications signup process.  Here is some rough code I've put together from other posts in this forum - but when I attempt to login w/ the username and password I fail to login.  It's as if I am missing some additional details.  Please see my code below.  Your help very much appreciated.


include('inc/functions.php');

function generate_salt()
{
return random_str(8);
}

function salt_password($myPassword, $salt)
{
return md5(md5($salt).$myPassword);
}


$myUsername = "testuser";
$myPassword = "testuser";
$email = "[email protected]";
$salt = generate_salt();
$usergroup = 2;
$regdate = "1418678052";

$myPassword = salt_password($myPassword, $salt);

$conn = mysql_connect($hostname,$username, $password);
mysql_select_db($dbname); 

$sql = "INSERT INTO `mybb_users` (`uid`, `username`, `password`, `salt`, `loginkey`, `email`, `usergroup`, `regdate`) VALUES (NULL, \"$myUsername\", \"$myPassword\",  \"$salt\", \"$loginkey\",\"$email\", \"$usergroup\", \"$regdate\")";
$result = mysql_query($sql) or die("<p>Saving myBB User Failed.</p><p>$sql</p><p><strong>" . mysql_error() .".</strong></p><p>Please contact our webmaster!</p>");

print "<p>If no error, saving myBB user was successful!</p>";

mysql_close($conn);


The first mistake is that you're not using md5() on the password itself before salting it: https://github.com/mybb/mybb/blob/featur...r.php#L174 Not checking the rest for now since that may fix it.
Thank you for your very quick reply!

Ok - I changed

$myPassword = "testuser";

to

$myPassword = md5("testuser");

thus using md5 on the password itself. Still same results, not able to login as it fails.
Where is $loginkey var defined?
$loginkey is defined in the included functions.php file.

WooHoo!  After adding a loginkey assignment this works!  Thank you Destroy666

<?php
include('inc/functions.php');

function generate_salt()
{
return random_str(8);
}

function generate_loginkey()
{
return random_str(50);
}

function salt_password($myPassword, $salt)
{
return md5(md5($salt).$myPassword);
}



if ($myUsername && $myPassword && $email){

$myPassword = md5($myPassword);

$loginkey = generate_loginkey();
$salt = generate_salt();
$usergroup = 2;
$regdate = "1418678052";

$myPassword = salt_password($myPassword, $salt);

$hostname="[ENTER MYSQL HOST]";
$username="[ENTER MYSQL USERNAME]";
$password="[ENTER MYSQL PASSWORD]";
$dbname="ddzdaner_mybb";

$conn = mysql_connect($hostname,$username, $password);
mysql_select_db($dbname);


$sql = "INSERT INTO mybb_users (uid, username, password, salt, loginkey, email, usergroup, regdate) VALUES (NULL, \"$myUsername\", \"$myPassword\",  \"$salt\", \"$loginkey\",\"$email\", \"$usergroup\", \"$regdate\")";

$result = mysql_query($sql) or die("<p>Saving myBB User Failed.</p><p>$sql</p><p><strong>" . mysql_error() .".</strong></p><p>Please contact our webmaster!</p>");

print "<p>If no error, saving myBB user was successful!</p>";

mysql_close($conn);

}

?>
where do i put this php to use it please?

thanks
(2014-12-19, 07:01 PM)Destroy666 Wrote: [ -> ]Where is $loginkey var defined?

(2014-12-30, 01:28 PM)jsnull Wrote: [ -> ]$loginkey is defined in the included functions.php file.

WooHoo!  After adding a loginkey assignment this works!  Thank you Destroy666

<?php
include('inc/functions.php');

function generate_salt()
{
return random_str(8);
}

function generate_loginkey()
{
return random_str(50);
}

function salt_password($myPassword, $salt)
{
return md5(md5($salt).$myPassword);
}



if ($myUsername && $myPassword && $email){

$myPassword = md5($myPassword);

$loginkey = generate_loginkey();
$salt = generate_salt();
$usergroup = 2;
$regdate = "1418678052";

$myPassword = salt_password($myPassword, $salt);

$hostname="[ENTER MYSQL HOST]";
$username="[ENTER MYSQL USERNAME]";
$password="[ENTER MYSQL PASSWORD]";
$dbname="ddzdaner_mybb";

$conn = mysql_connect($hostname,$username, $password);
mysql_select_db($dbname);


$sql = "INSERT INTO mybb_users (uid, username, password, salt, loginkey, email, usergroup, regdate) VALUES (NULL, \"$myUsername\", \"$myPassword\",  \"$salt\", \"$loginkey\",\"$email\", \"$usergroup\", \"$regdate\")";

$result = mysql_query($sql) or die("<p>Saving myBB User Failed.</p><p>$sql</p><p><strong>" . mysql_error() .".</strong></p><p>Please contact our webmaster!</p>");

print "<p>If no error, saving myBB user was successful!</p>";

mysql_close($conn);

}

?>
(2016-09-05, 06:29 PM)theonlyjazzer Wrote: [ -> ]where do i put this php to use it please?

You need to make new page with login boxes, and to point
Quote:include('inc/functions.php');

this line to your forum directory. If external page you created is outside da forum directory, may look somethng like that:
Quote:include('../forums/inc/functions.php');
You don't need this much work.. pick the method to register user from member.php