I'm setting up a Moodle environment and I need users to be able to login via an external site using their credentials from that site. Ideally they would go to the website, login in, and then click a button that will send them to Moodle along with their account information.
Once they get to Moodle, Moodle will check to see if the account information already exists. If so it will login, otherwise it will create the account and login.
I already have the Moodle environment set up, as well as the login site. The Moodle site is not allowed to access the database on the login site, and the users shouldn't have to enter their information again at any point.
I've already spent several hours attempting to work backwards from a plugin that accomplishes something similar between Moodle and social networking sites (facebook, twitter, google+, etc) but made no progress, as well as from a plugin that linked Moodle with Joomla, and I've searched through here and other forums for anything I could find similar to what I need to accomplish to no avail. Any help would be very appreciated.
Edit: I forgot to mention that the Moodle version is 2.5.4
Edit: The following will create a new user with data posted to the "login/index.php" page. This is currently very incomplete and probably dangerous to implement on a production server. Updated versions will be posted as I continue to work on it, suggestions are more than welcome.
global $CFG, $DB;
require_once($CFG->dirroot.'/user/profile/lib.php');
require_once($CFG->libdir.'/authlib.php');
$newuser = $DB->get_record('user', array('id'=>'1'));
$newuser->auth = 'manual';
$newuser->username = $frm->username;
$newuser->password = hash_internal_user_password($frm->password);
$newuser->username = $DB->insert_record('user', $newuser);
/// Save any custom profile field information
profile_save_data($newuser);
$newuser = $DB->get_record('user', array('id'=>$newuser->username));
events_trigger('user_created', $newuser);