diff options
Diffstat (limited to 'modules/user')
-rw-r--r-- | modules/user/user.module | 7 | ||||
-rw-r--r-- | modules/user/user.test | 25 |
2 files changed, 27 insertions, 5 deletions
diff --git a/modules/user/user.module b/modules/user/user.module index d464a7a7b..5411d35e9 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -2169,7 +2169,7 @@ function user_login_final_validate($form, &$form_state) { function user_authenticate($name, $password) { $uid = FALSE; if (!empty($name) && !empty($password)) { - $account = db_query("SELECT * FROM {users} WHERE name = :name AND status = 1", array(':name' => $name))->fetchObject(); + $account = user_load_by_name($name); if ($account) { // Allow alternate password hashing schemes. require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc'); @@ -2181,10 +2181,7 @@ function user_authenticate($name, $password) { if (user_needs_new_hash($account)) { $new_hash = user_hash_password($password); if ($new_hash) { - db_update('users') - ->fields(array('pass' => $new_hash)) - ->condition('uid', $account->uid) - ->execute(); + user_save($account, array('pass' => $new_hash)); } } } diff --git a/modules/user/user.test b/modules/user/user.test index a49a89b5c..d999c85e2 100644 --- a/modules/user/user.test +++ b/modules/user/user.test @@ -367,6 +367,31 @@ class UserLoginTestCase extends DrupalWebTestCase { } /** + * Test that user password is re-hashed upon login after changing $count_log2. + */ + function testPasswordRehashOnLogin() { + // Load password hashing API. + require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc'); + // Set initial $count_log2 to the default, DRUPAL_HASH_COUNT. + variable_set('password_count_log2', DRUPAL_HASH_COUNT); + // Create a new user and authenticate. + $account = $this->drupalCreateUser(array()); + $password = $account->pass_raw; + $this->drupalLogin($account); + $this->drupalLogout(); + // Load the stored user. The password hash should reflect $count_log2. + $account = user_load($account->uid); + $this->assertIdentical(_password_get_count_log2($account->pass), DRUPAL_HASH_COUNT); + // Change $count_log2 and log in again. + variable_set('password_count_log2', DRUPAL_HASH_COUNT + 1); + $account->pass_raw = $password; + $this->drupalLogin($account); + // Load the stored user, which should have a different password hash now. + $account = user_load($account->uid, TRUE); + $this->assertIdentical(_password_get_count_log2($account->pass), DRUPAL_HASH_COUNT + 1); + } + + /** * Make an unsuccessful login attempt. * * @param $account |