function user_authenticate in Drupal 4
Same name and namespace in other branches
- 5 modules/user/user.module \user_authenticate()
- 6 modules/user/user.module \user_authenticate()
- 7 modules/user/user.module \user_authenticate()
3 calls to user_authenticate()
- blogapi_validate_user in modules/
blogapi.module - Ensure that the given user has permission to edit a blog.
- user_login_validate in modules/
user.module - user_register_submit in modules/
user.module
File
- modules/
user.module, line 970 - Enables the user registration and login system.
Code
function user_authenticate($name, $pass) {
global $user;
// Try to log in the user locally. Don't set $user unless successful.
if ($account = user_load(array(
'name' => $name,
'pass' => $pass,
'status' => 1,
))) {
$user = $account;
}
// Strip name and server from ID:
if ($server = strrchr($name, '@')) {
$name = substr($name, 0, strlen($name) - strlen($server));
$server = substr($server, 1);
}
// When possible, determine corresponding external auth source. Invoke
// source, and log in user if successful:
if (!$user->uid && $server && ($result = user_get_authmaps("{$name}@{$server}"))) {
if (module_invoke(key($result), 'auth', $name, $pass, $server)) {
$user = user_external_load("{$name}@{$server}");
watchdog('user', t('External load by %user using module %module.', array(
'%user' => theme('placeholder', $name . '@' . $server),
'%module' => theme('placeholder', key($result)),
)));
}
else {
$error = t('Invalid password for %s.', array(
'%s' => theme('placeholder', $name . '@' . $server),
));
}
}
else {
if (!$user->uid && $server) {
foreach (module_list() as $module) {
if (module_hook($module, 'auth')) {
if (module_invoke($module, 'auth', $name, $pass, $server)) {
if (variable_get('user_register', 1) == 1) {
$account = user_load(array(
'name' => "{$name}@{$server}",
));
if (!$account->uid) {
// Register this new user.
$user = user_save('', array(
'name' => "{$name}@{$server}",
'pass' => user_password(),
'init' => "{$name}@{$server}",
'status' => 1,
"authname_{$module}" => "{$name}@{$server}",
));
watchdog('user', t('New external user: %user using module %module.', array(
'%user' => theme('placeholder', $name . '@' . $server),
'%module' => theme('placeholder', $module),
)), WATCHDOG_NOTICE, l(t('edit'), 'user/' . $user->uid . '/edit'));
break;
}
}
}
}
}
}
}
return $user;
}