Customizing SMF > Portals, Bridges, and Integrations
custom integration with another db
elevatorguy:
Hello, here is my situation:
I have a game server which uses a mysql db to store the player login info (username, and sha-512 of the password).
I am setting up a smf forum that I want the game players to be able to login from. I do not want people to register from the smf register page, I only want the players that have played on my server to be able to create an account.
To disable registration, I simply have Register.php redirect to a page about the game server.
I try to login "Password incorrect".
loginout.php:
what I changed was I added this line for $other_passwords[]
--- Code: --- $other_passwords[] = hash('sha-512', $_POST['passwrd']);
--- End code ---
and then for actually checking the other db:
right after
--- Code: --- // Let them try again, it didn't match anything...
if ($smcFunc['db_num_rows']($request) == 0)
{
$context['login_errors'] = array($txt['username_no_exist']);
--- End code ---
I insert :
--- Code: --- // check if they are a gamer
$password = $_POST['passwrd'];
$username = $_POST['user'];
$dbnamefound = false;
$webhash = hash('sha512', $password);
$webname = str_replace("'", "\'", $username);
$conngame = mysql_connect("localhost", $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($gamedbname, $conngame) or die(mysql_error());
$gquery = "SELECT * FROM Users WHERE Username = '".$webname."'";
$gqresult = mysql_query($gquery, $conngame) or die(mysql_error());
while($row = mysql_fetch_array($gqresult))
{
$dbnamefound = true;
$gamedbhash = $row['Password'];
}
mysql_close($conngame);
if($username)
{
if($dbnamefound)
{
$hashlower = hash('sha512', $password);
if($gamedbhash == strtoupper($hashlower)) // because in the db the hash is in uppercase
{
// password correct
$connadduser = mysql_connect("localhost", $forumdbuser, $forumdbpassword);
mysql_select_db('gameforum_smf', $connadduser) or die(mysql_error());
$auquery = "INSERT INTO `gameforum_smf`.`smf_members` (`member_name`, `passwd`) VALUES ('".$username."', '".sha1($password . $sc)."');";
$auresult = mysql_query($auquery, $connadduser) or die(mysql_error());
while($row = mysql_fetch_array($auresult))
{
}
mysql_close($connadduser);
goto beginning;
}
}
}
// end game user db check
--- End code ---
If it finds the user in the game db then I have it create an entry in the smf members table, and then I had to (oh no !), use a goto statement to the beginning of the method, so that the user can login to the smf user that was just created without having to type their info again. (I wouldn't mind a better way to do this)
I just can't figure out where I went wrong here, any help would be greatly appreciated! :)
EDIT: I found that for some reason when I try to use $_POST['passwrd'] it is empty? why is this, or what variable am I supposed to be using to get the password?
Andre N:
it looks like it should be 'passwrd'... try dumping $_POST or $_REQUEST to see what you get
if you're always logging in from SMF, a better way to do this might be to use the integration hook 'integrate_login'
Basically the user will login from SMF and if the login authenticates, the hook will allow you to do whatever to login or register/login the user in your other system at that point.
Here's more info on the hooks:
http://www.simplemachines.org/community/index.php?topic=453008.0
Arantor:
$_POST['passwrd'] is not normally set for passwords going into SMF, because they're usually hashed in JavaScript before logging in, which means of course you can't make it work to accept SHA-512 passwords (because the hash you get is SHA1)
In any case, if you're adding to $other_passwords, that only works if there's no passwordSalt value, which is only true if you're coming from another system (or you've manually added the row without it), otherwise it will be using the supplied password and normal hash method.
dharma16:
Hi elevatorguy
Did you get this working? I'm asking because I too want the user to register outside SMF. The other option I have I guess is to disable the registration from SMF. Then from my website (separate to smf) when it gets to the registration component I redirect them to smf after they fill in the required details for my website database however some of that information includes the email address.
Can someone suggest another way. I've looked at the API but that's only handy for me if they wish to login to SMF outside of SMF (from my website). It's the initial registration that I want to capture first in my website before registering them for smf.
Please note I'm very new to SMF however if you can pinpoint me to the correct php scripts to look at and suggested code changes I would appreciate it.
Kindred:
I think you have missed the point of the API and the hooks system. Both will work with registration as well as login. They tie an outside system into SMF.
In the case of the API, the outside system is primary...
In the case of the hooks, SMF is primary...
But, in both cases, registration, login, etc are all linked. What happens on one side is transferred to the other
Navigation
[0] Message Index
[#] Next page
Go to full version