Jump to content

Remote Login


Nils

Recommended Posts

Posted

Hi,

This works with the current release :

if ((isset($_POST["token"], $_COOKIE["CSRFtoken"])) && ($_POST["token"] == $_COOKIE["CSRFtoken"])) {
   require_once($_SERVER['DOCUMENT_ROOT'].'/forums/init.php');

   $IPSLogin = new \IPS\Login\Internal;
   $IPSLogin->init();

   $member = \IPS\Member::load( $_POST['username'], 'name' );

   if ( $member->member_id ) {
      if ( \IPS\Login\Handler::findMethod('IPS\Login\Handler\Standard')->authenticatePasswordForMember($member, \IPS\Request::i()->password ) )	{
         $device = \IPS\Member\Device::loadOrCreate($member);
         $device->updateAfterAuthentication( TRUE ); // TRUE is "Remember Me"
         echo 1;
      } else {
         echo 0; // Password incorrect
      }
   }
}

 

Posted
7 hours ago, Jibeji said:

Hi,

This works with the current release :

*snip*

Hey, thanks for the reply. Unfortunately my script stops at

$IPSLogin = new \IPS\Login\Internal;

And here is the entire script for reference.
 

<?php

$path	= '';
require_once $path . 'init.php';

$IPSLogin = new \IPS\Login\Internal;
$IPSLogin->init();

$member = \IPS\Member::load( $_POST['username'], 'name' );

if ( $member->member_id ) 
{
  if ( \IPS\Login\Handler::findMethod('IPS\Login\Handler\Standard')->authenticatePasswordForMember($member, \IPS\Request::i()->password ) )	{
     $device = \IPS\Member\Device::loadOrCreate($member);
     $device->updateAfterAuthentication( TRUE ); // TRUE is "Remember Me"
     \IPS\Output::i()->json(
    	array(
    		"status" => "SUCCESS",
    		"connect_id" => $member->member_id,
    	)
    );
  } else {
     \IPS\Output::i()->json( // Password incorrect
    	array(
    		'status' => 'FAILED',
    		'msg' => 'ACCOUNT_INVALID_PASSWORD',
    	) ); 
  }
}

?>

I'm not much of a PHP guy, I was initially just looking for where IPS does its login code/logic and planned to rebuild it in C++, but had no luck finding it.

Thanks.

Posted
9 minutes ago, Jibeji said:

That probably means that this fails:


require_once $path . 'init.php';

 

Doesn't seem like it fails. I have the .php in the same directory as init.php. index.php just does

require_once 'init.php';

and that doesn't throw any errors or anything either. Not sure why `$IPSLogin = new \IPS\Login\Internal;` is causing the script to stop.

Posted
41 minutes ago, Stuart Silvester said:

`\IPS\Login\Internal` does not exist in 4.3 or newer. You don't need either of these lines


$IPSLogin = new \IPS\Login\Internal;
$IPSLogin->init();

 

Awesome, thanks. Got it working.

Thanks @Jibeji, the rest of your code worked perfectly.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...