Advertisement

Joomla Auto Login

General questions relating to Joomla! 3.x.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10
Locked
Elpidios
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Fri Jul 17, 2009 12:27 am

Joomla Auto Login

Post by Elpidios » Tue Jul 28, 2015 4:56 pm

Hello.
I know that a plugin that exist but is not suitable for me.

What I want to do.

I have two sites. One custom and one Joomla

My users sign ups through a my custom page and I import their data to Joomla

When someone tries to login through my custom site I want automatically to login on Joomla site. The passwords are same with hash key

Advertisement
Elpidios
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Fri Jul 17, 2009 12:27 am

Re: Joomla Auto Login

Post by Elpidios » Tue Jul 28, 2015 10:06 pm

I found this code on the net....As I can understand is working but not save the sessions..how can i save session?


/**
* Joomla! External authentication script
*
* @author vdespa
* Version 1.0
*
* Code adapted from /index.php
*
* @package Joomla.Site
*
* @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

if (version_compare(PHP_VERSION, '5.3.1', '<'))
{
die('Your host needs to use PHP 5.3.1 or higher to run this version of Joomla!');
}

/**
* Constant that is checked in included files to prevent direct access.
* define() is used in the installation folder rather than "const" to not error for PHP 5.2 and lower
*/
define('_JEXEC', 1);


if (file_exists(__DIR__ . '/defines.php'))
{
include_once __DIR__ . '/defines.php';
}

if (!defined('_JDEFINES'))
{
define('JPATH_BASE', __DIR__);
require_once JPATH_BASE . '/includes/defines.php';
}

require_once JPATH_BASE . '/includes/framework.php';

// Instantiate the application.
$app = JFactory::getApplication('site');



// JFactory
require_once (JPATH_BASE .'/libraries/joomla/factory.php');


// Hardcoded for now
$credentials['username'] = 'admin';
$credentials['password'] = 'aelara1930';


// Get a database object
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('id, password')
->from('#__users')
->where('username=' . $db->quote($credentials['username']));

$db->setQuery($query);
$result = $db->loadObject();

if ($result)
{
$match = JUserHelper::verifyPassword($credentials['password'], $result->password, $result->id);

if ($match === true)
{
// Bring this in line with the rest of the system
$user = JUser::getInstance($result->id);

echo 'Joomla! Authentication was successful!' . '<br>';
echo 'Joomla! Token is:' . JHTML::_( 'form.token' );

//perform the login action
$error = $app->login($credentials);
$logged_user = JFactory::getUser();
var_dump($logged_user );

//redirect logged in user
$app->redirect('index.php');
}
else
{
// Invalid password
// Prmitive error handling
echo 'Joomla! Token is:' . JHTML::_( 'form.token' ) . '<br>';
die('Invalid password');
}
} else {
// Invalid user
// Prmitive error handling
die('Cound not find user in the database');
}
?>

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 31330
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Joomla Auto Login

Post by Per Yngve Berg » Mon Aug 03, 2015 2:15 pm

Review JFusion.
http://www.jfusion.org

Advertisement

Locked

Return to “General Questions/New to Joomla! 3.x”