Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.1224
diff -u -p -r1.1224 user.module
--- modules/user/user.module	30 Nov 2010 23:55:11 -0000	1.1224
+++ modules/user/user.module	8 Dec 2010 09:40:53 -0000
@@ -1149,8 +1149,6 @@ function user_account_form(&$form, &$for
  * @see user_account_form()
  */
 function user_validate_current_pass(&$form, &$form_state) {
-  global $user;
-
   $account = $form['#user'];
   foreach ($form_state['values']['current_pass_required_values'] as $key => $name) {
     // This validation only works for required textfields (like mail) or
@@ -1158,7 +1156,7 @@ function user_validate_current_pass(&$fo
     // that prevent them from being empty if they are changed.
     if ((strlen(trim($form_state['values'][$key])) > 0) && ($form_state['values'][$key] != $account->$key)) {
       require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
-      $current_pass_failed = empty($form_state['values']['current_pass']) || !user_check_password($form_state['values']['current_pass'], $user);
+      $current_pass_failed = empty($form_state['values']['current_pass']) || !user_check_password($form_state['values']['current_pass'], $account);
       if ($current_pass_failed) {
         form_set_error('current_pass', t("Your current password is missing or incorrect; it's required to change the %name.", array('%name' => $name)));
         form_set_error($key);
Index: modules/user/user.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.test,v
retrieving revision 1.108
diff -u -p -r1.108 user.test
--- modules/user/user.test	30 Nov 2010 23:55:11 -0000	1.108
+++ modules/user/user.test	8 Dec 2010 09:40:53 -0000
@@ -2069,3 +2069,48 @@ class UserAuthmapAssignmentTestCase exte
     }
   }
 }
+
+/**
+ * Tests user_validate_current_pass on a custom form.
+ */
+class UserValidateCurrentPassCustomForm extends DrupalWebTestCase {
+
+  public static function getInfo() {
+    return array(
+      'name' => 'User validate current pass custom form',
+      'description' => 'Test that user_validate_current_pass is usable on a custom form.',
+      'group' => 'User',
+    );
+  }
+
+  /**
+   * User with permission to view content.
+   */
+  protected $accessUser;
+
+  /**
+   * User permission to administer users.
+   */
+  protected $adminUser;
+
+  function setUp() {
+    parent::setUp('user_form_test');
+    // Create two users
+    $this->accessUser = $this->drupalCreateUser(array('access content'));
+    $this->adminUser = $this->drupalCreateUser(array('administer users'));
+  }
+
+  /**
+   * Tests that user_validate_current_pass can be reused on a custom form.
+   */
+  function testUserValidateCurrentPassCustomForm() {
+    $this->drupalLogin($this->adminUser);
+
+    // Submit the custom form with the admin user using the access user's password.
+    $edit = array();
+    $edit['user_form_test_field'] = $this->accessUser->name;
+    $edit['current_pass'] = $this->accessUser->pass_raw;
+    $this->drupalPost('user_form_test_current_password/' . $this->accessUser->uid, $edit, t('Test'));
+    $this->assertText(t('The password has been validated and the form submitted successfully.'));
+  }
+}
Index: modules/user/tests/user_form_test.info
===================================================================
RCS file: modules/user/tests/user_form_test.info
diff -N modules/user/tests/user_form_test.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/user/tests/user_form_test.info	8 Dec 2010 09:40:42 -0000
@@ -0,0 +1,8 @@
+; $Id$
+name = "User module form tests"
+description = "Support module for user form testing."
+package = Testing
+version = VERSION
+core = 7.x
+files[] = user_form_test.module
+hidden = TRUE
Index: modules/user/tests/user_form_test.module
===================================================================
RCS file: modules/user/tests/user_form_test.module
diff -N modules/user/tests/user_form_test.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/user/tests/user_form_test.module	8 Dec 2010 09:40:42 -0000
@@ -0,0 +1,65 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Dummy module implementing a form to test user password validation
+ */
+
+/**
+ * Implements hook_menu().
+ *
+ * Sets up a form that allows a user to validate password.
+ */
+function user_form_test_menu() {
+  $items = array();
+  $items['user_form_test_current_password/%user'] = array(
+    'title' => 'User form test for current password validation',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('user_form_test_current_password',1),
+    'access arguments' => array('administer users'),
+    'type' => MENU_SUGGESTED_ITEM,
+  );
+  return $items;
+}
+
+/**
+ * A test form for user_validate_current_pass().
+ */
+function user_form_test_current_password($form, &$form_state, $account) {
+  $account->user_form_test_field = '';
+  $form['#user'] = $account;
+
+  $form['user_form_test_field'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Test field'),
+    '#description' => t('A field that would require a correct password to change.'),
+    '#required' => TRUE,
+  );
+  
+  $form['current_pass'] = array(
+    '#type' => 'password',
+    '#title' => t('Current password'),
+    '#size' => 25,
+    '#description' => t('Enter your current password'),
+  );
+
+  $form['current_pass_required_values'] = array(
+    '#type' => 'value',
+    '#value' => array('user_form_test_field' => t('Test field')),
+  );
+
+  $form['#validate'][] = 'user_validate_current_pass';
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Test'),
+  );
+  return $form;
+}
+
+/**
+ * Submit function for the test form for user_validate_current_pass().
+ */
+function user_form_test_current_password_submit($form, &$form_state) {
+  drupal_set_message(t('The password has been validated and the form submitted successfully.'));
+}
