function joomla_authenticate in Joomla to Drupal 6
Same name and namespace in other branches
- 7.2 joomla.module \joomla_authenticate()
- 7 joomla.module \joomla_authenticate()
1 call to joomla_authenticate()
File
- ./
joomla.module, line 895 - The joomla module used for migrate Joomla to Drupal.
Code
function joomla_authenticate($form_values = array()) {
global $user;
if (!empty($user->uid)) {
// User has already sucessfully authenticated
return;
}
if (form_get_errors() || empty($form_values['name']) || empty($form_values['pass'])) {
return;
}
$account = user_load(array(
'name' => $form_values['name'],
'status' => 1,
));
// The user doesn't exist
if (!$account) {
return;
}
// See if the user has a password record from Joomla import
$joomla_user = db_fetch_object(db_query('SELECT * FROM {joomla_users} WHERE uid = %d', $account->uid));
if (!$joomla_user) {
return;
}
/**
* If the password doesn't contain a colon, it is an unsalted password.
* It will have been inserted into the drupal users table during the
* import, and to get here the Drupal login must have already failed
* against it, so nothing left to do
*/
list($password, $salt) = explode(':', $joomla_user->password, 2);
if (!$salt) {
return;
}
// Check the salt + supplied password against the md5sum
if (md5($form_values['pass'] . $salt) == $password) {
$user = $account;
watchdog('joomla', 'Converting password for user @name (Joomla id @juid)', array(
'@name' => $user->name,
'@juid' => $joomla_user->juid,
));
// Update the users Drupal password
user_save($user, array(
'pass' => $form_values['pass'],
));
$joomla_user->converted = 1;
drupal_write_record('joomla_users', $joomla_user, array(
'uid',
));
user_authenticate_finalize($form_values);
return $user;
}
}