=== modified file 'modules/blogapi/blogapi.module'
--- modules/blogapi/blogapi.module	2007-06-30 19:46:54 +0000
+++ modules/blogapi/blogapi.module	2007-08-30 16:31:23 +0000
@@ -507,7 +507,7 @@ function blogapi_error($message) {
 function blogapi_validate_user($username, $password) {
   global $user;
 
-  $user = user_authenticate($username, $password);
+  $user = user_authenticate(array('name' => $username, 'pass' => $password));
 
   if ($user->uid) {
     if (user_access('edit own blog', $user)) {

=== modified file 'modules/drupal/drupal.module'
--- modules/drupal/drupal.module	2007-08-21 08:15:59 +0000
+++ modules/drupal/drupal.module	2007-08-30 16:31:23 +0000
@@ -340,6 +340,6 @@ function drupal_menu() {
  */
 function drupal_login($username, $password) {
   if (variable_get('drupal_authentication_service', 0)) {
-    return user_authenticate($username, $password);
+    return user_authenticate(array('name' => $username, 'pass' => $password));
   }
 }

=== modified file 'modules/poll/poll.module'
--- modules/poll/poll.module	2007-08-26 07:46:10 +0000
+++ modules/poll/poll.module	2007-08-30 16:23:00 +0000
@@ -299,6 +299,24 @@ function poll_load($node) {
   while ($choice = db_fetch_array($result)) {
     $poll->choice[$choice['chorder']] = $choice;
   }
+
+  // Determine whether or not this user is allowed to vote
+  $poll->allowvotes = FALSE;
+  if (user_access('vote on polls') && $poll->active) {
+    if ($user->uid) {
+      $result = db_fetch_object(db_query('SELECT chorder FROM {poll_votes} WHERE nid = %d AND uid = %d', $node->nid, $user->uid));
+    }
+    else {
+      $result = db_fetch_object(db_query("SELECT chorder FROM {poll_votes} WHERE nid = %d AND hostname = '%s'", $node->nid, ip_address()));
+    }
+    if (isset($result->chorder)) {
+      $poll->vote = $result->chorder;
+    }
+    else {
+      $poll->vote = -1;
+      $poll->allowvotes = TRUE;
+    }
+  }
   return $poll;
 }
 
@@ -364,25 +382,6 @@ function poll_view($node, $teaser = FALS
   global $user;
   $output = '';
 
-  // Determine whether or not this user is allowed to vote
-  $poll->allowvotes = FALSE;
-  if (user_access('vote on polls') && $poll->active) {
-    if ($user->uid) {
-      $result = db_fetch_object(db_query('SELECT chorder FROM {poll_votes} WHERE nid = %d AND uid = %d', $node->nid, $user->uid));
-    }
-    else {
-      $result = db_fetch_object(db_query("SELECT chorder FROM {poll_votes} WHERE nid = %d AND hostname = '%s'", $node->nid, ip_address()));
-    }
-    if (isset($result->chorder)) {
-      $poll->vote = $result->chorder;
-    }
-    else {
-      $poll->vote = -1;
-      $poll->allowvotes = TRUE;
-    }
-  }
-
-
   // Special display for side-block
   if ($block) {
     // No 'read more' link

=== modified file 'modules/user/user.module'
--- modules/user/user.module	2007-08-29 14:57:48 +0000
+++ modules/user/user.module	2007-08-30 16:33:09 +0000
@@ -1208,7 +1208,7 @@ function user_login_name_validate($form,
  * @return void
  **/
 function user_login_authenticate_validate($form, &$form_state) {
-  user_authenticate($form_state['values']['name'], trim($form_state['values']['pass']));
+  user_authenticate($form_state['values']);
 }
 
 /**
@@ -1228,36 +1228,53 @@ function user_login_final_validate($form
 /**
  * Try to log in the user locally.
  *
+ * @param $form_values
+ *   An array containing the form values, including 'name' and 'pass'.
  * @return
  *   A $user object, if successful.
  **/
-function user_authenticate($name, $pass) {
+function user_authenticate($form_values) {
   global $user;
 
-  if ($account = user_load(array('name' => $name, 'pass' => $pass, 'status' => 1))) {
+  // Name and pass are required.
+  if (isset($form_values['name']) and isset($form_values['pass']) and $account = user_load(array('name' => $form_values['name'], 'pass' => $form_values['pass'], 'status' => 1))) {
     $user = $account;
+    user_authenticate_tasks($form_values);
     return $user;
   }
 }
 
 /**
- * A validate handler on the login form. Update user's login timestamp, fire hook_user('login), and generate new session ID.
+ * Completes the user authentication by updating the user's login timestamp,
+ * firing hook_user('login), and generating a new session ID.
  *
- * @return void
+ * @param $form_values
+ *   An array containing the form values.
+ * @return
+ *   void
  **/
-function user_login_submit($form, &$form_state) {
+function user_authenticate_tasks($form_values = array()) {
   global $user;
-  if ($user->uid) {
-    watchdog('user', 'Session opened for %name.', array('%name' => $user->name));
 
-    // Update the user table timestamp noting user has logged in.
-    db_query("UPDATE {users} SET login = %d WHERE uid = %d", time(), $user->uid);
+  watchdog('user', 'Session opened for %name.', array('%name' => $user->name));
+
+  // Update the user table timestamp noting user has logged in.
+  db_query("UPDATE {users} SET login = %d WHERE uid = %d", time(), $user->uid);
 
-    user_module_invoke('login', $form_state['values'], $user);
+  user_module_invoke('login', $form_values, $user);
 
-    sess_regenerate();
+  sess_regenerate();
+}
+
+/**
+ * A validate handler on the login form.
+ *
+ * @return void
+ **/
+function user_login_submit($form, &$form_state) {
+  global $user;
+  if ($user->uid) {
     $form_state['redirect'] = 'user/'. $user->uid;
-    return;
   }
 }
 
@@ -1365,14 +1382,12 @@ function user_pass_reset(&$form_state, $
         // First stage is a confirmation form, then login
         if ($action == 'login') {
           watchdog('user', 'User %name used one-time login link at time %timestamp.', array('%name' => $account->name, '%timestamp' => $timestamp));
-          // Update the user table noting user has logged in.
-          // And this also makes this hashed password a one-time-only login.
-          db_query("UPDATE {users} SET login = %d WHERE uid = %d", time(), $account->uid);
           // Now we can set the new user.
           $user = $account;
+          // Update the user table noting user has logged in.
+          // And this also makes this hashed password a one-time-only login.
+          user_authenticate_tasks($form_state['values']);
           // And proceed with normal login, going to user page.
-          $edit = array();
-          user_module_invoke('login', $edit, $user);
           drupal_set_message(t('You have just used your one-time login link. It is no longer necessary to use this link to login. Please change your password.'));
           drupal_goto('user/'. $user->uid .'/edit');
         }
@@ -1526,7 +1541,7 @@ function user_register_submit($form, &$f
       drupal_set_message(t('</p><p> Your password is <strong>%pass</strong>. You may change your password below.</p>', array('%pass' => $pass)));
     }
 
-    user_authenticate($account->name, trim($pass));
+    user_authenticate(array_merge($form_state['values'], $merge_data));
 
     $form_state['redirect'] = 'user/1/edit';
     return;
@@ -1540,7 +1555,7 @@ function user_register_submit($form, &$f
     else if (!variable_get('user_email_verification', TRUE) && $account->status && !$admin) {
       // No e-mail verification is required, create new user account, and login user immediately.
       _user_mail_notify('register_no_approval_required', $account);
-      if (user_authenticate($account->name, trim($pass))) {
+      if (user_authenticate(array_merge($form_state['values'], $merge_data))) {
         drupal_set_message(t('Registration succesful. You are now logged in.'));
       }
       $form_state['redirect'] = '';

