/[drupal]/drupal/modules/user/user.install
ViewVC logotype

Diff of /drupal/modules/user/user.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.7 by dries, Sat Mar 15 12:31:29 2008 UTC revision 1.8 by dries, Mon Mar 31 20:50:05 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: user.install,v 1.6 2008/02/18 16:53:36 dries Exp $  // $Id: user.install,v 1.7 2008/03/15 12:31:29 dries Exp $
3    
4  /**  /**
5   * Implementation of hook_schema().   * Implementation of hook_schema().
# Line 150  function user_schema() { Line 150  function user_schema() {
150        ),        ),
151        'pass' => array(        'pass' => array(
152          'type' => 'varchar',          'type' => 'varchar',
153          'length' => 32,          'length' => 128,
154          'not null' => TRUE,          'not null' => TRUE,
155          'default' => '',          'default' => '',
156          'description' => t("User's password (md5 hash)."),          'description' => t("User's password (hashed)."),
157        ),        ),
158        'mail' => array(        'mail' => array(
159          'type' => 'varchar',          'type' => 'varchar',
# Line 295  function user_schema() { Line 295  function user_schema() {
295    return $schema;    return $schema;
296  }  }
297    
298    /**
299     * @defgroup user-updates-6.x-to-7.x User updates from 6.x to 7.x
300     * @{
301     */
302    
303    /**
304     * Increase the length of the password field to accommodate better hashes.
305     *
306     * Also re-hashes all current passwords to improve security. This may be a
307     * lengthy process, and is performed batch-wise.
308     */
309    function user_update_7000(&$sandbox) {
310      $ret = array('#finished' => 0);
311      // Lower than DRUPAL_HASH_COUNT to make the update run at a reasonable speed.
312      $hash_count_log2 = 11;
313      // Multi-part update.
314      if (!isset($sandbox['user_from'])) {
315        db_change_field($ret, 'users', 'pass', 'pass', array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''));
316        $sandbox['user_from'] = 0;
317        $sandbox['user_count'] = db_result(db_query("SELECT COUNT(uid) FROM {users}"));
318      }
319      else {
320        require_once variable_get('password_inc', './includes/password.inc');
321        //  Hash again all current hashed passwords.
322        $has_rows = FALSE;
323        // Update this many per page load.
324        $count = 1000;
325        $result = db_query_range("SELECT uid, pass FROM {users} WHERE uid > 0 ORDER BY uid", $sandbox['user_from'], $count);
326        while ($account = db_fetch_array($result)) {
327           $has_rows = TRUE;
328           $new_hash = user_hash_password($account['pass'], $hash_count_log2);
329           if ($new_hash) {
330             // Indicate an updated password.
331             $new_hash  = 'U'. $new_hash;
332             db_query("UPDATE {users} SET pass = '%s' WHERE uid = %d", $new_hash, $account['uid']);
333           }
334        }
335        $ret['#finished'] = $sandbox['user_from']/$sandbox['user_count'];
336        $sandbox['user_from'] += $count;
337        if (!$has_rows) {
338          $ret['#finished'] = 1;
339          $ret[] = array('success' => TRUE, 'query' => "UPDATE {users} SET pass = 'U'. user_hash_password(pass) WHERE uid > 0");
340        }
341      }
342      return $ret;
343    }
344    
345    /**
346     * @} End of "defgroup user-updates-6.x-to-7.x"
347     * The next series of updates should start at 8000.
348     */
349    

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.3