Currently Importing users via CSV is great. The only thing i don't understand is why there isn't a mapping field for a user's password. I think this would be a great addition to the module. Is there an option for this in the works?

Comments

Onfire60’s picture

Title: Need an option to ipmort user with password via csv. » Need an option to import a user's password via csv.
alex_b’s picture

Title: Need an option to import a user's password via csv. » Mapper for user password
Status: Active » Postponed
Issue tags: -CSV, -Feeds, -user password, -CSV import

Is there an option for this in the works?

There isn't.

Postponing this issue. Feel free to set to active if you'd like to work on this.

arski’s picture

would love to have this too. Is it somehow trickier than just the username or email field?

willieseabrook’s picture

subscribe

willieseabrook’s picture

Version: 6.x-1.0-beta6 » 6.x-1.0-beta10
Status: Postponed » Needs review
StatusFileSize
new578 bytes

See attached patch. Only works if pass is plain text.

Due to the way user module md5s ->pass no matter what, would be a little extra to do an additional update after insert to manually update an md5 encrypted pass.

If theres any demand for that ping me. For now all i need is plain text.

micheleannj’s picture

Awesome timing -- thanks!

Anonymous’s picture

Good approach. This patch (in #5) is very simple and taps into Drupal's existing security framework. Thanks!

jackbravo’s picture

Status: Needs review » Active

Seems like this has not been ported to D7 version.

kehan’s picture

subscribing and +1 for d7

jyee’s picture

Version: 6.x-1.0-beta10 » 7.x-2.0-alpha3
Status: Active » Needs review
StatusFileSize
new729 bytes

Patch from #5 updated for Feeds 7.x-2.0-alpha3
Same file, same code, different line numbers... seemed to work in my basic testing.

Don't Use This File, See Following Comment
Sorry folks, forgot I was on my own site git repository and not from the Feeds git. This file isn't Drupal standards compliant (although it should work if your site is in Git and Feeds is in sites/all/modules/contrib/feeds

Status: Needs review » Needs work

The last submitted patch, password_mapper-914210-10-7.x_2.0_a3.patch, failed testing.

jyee’s picture

Status: Needs work » Needs review
StatusFileSize
new601 bytes

Updated patch using the git 7.x-2.x branch of Feeds. Previous patch file was incorrectly generated.

Status: Needs review » Needs work

The last submitted patch, password_mapper-914210-11-7.x_2.0.patch, failed testing.

jyee’s picture

Status: Needs work » Needs review

Automated test failing because there's no feeds_test... seems like an issue with the automated tester and not this patch. Setting back to 'needs review' for actually reviewing and testing.

Edit:
For those who don't want to apply a patch, you could simply create a module with this code in the .module file:

function HOOK_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
  if ($entity_type == 'user') {
    $targets['pass'] = array(
      'name' => t('Unencrypted Password'),
      'description' => t('The unencrypted user password.'),
    );
  } 
}

Where HOOK is the name of your module

Antoine Lafontaine’s picture

@willieseabrook

Your patch in #5 works great, but I'm also quite interested in a solution for importing already md5'ed passwords. You seem to be hinting for a solution. Would you care sharing it?

Thanks.

Antoine Lafontaine’s picture

Had a try at the problem myself and came with the following solution, wrapped in a small custom module.

<?php

function MODULENAME_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
  if ($entity_type == 'user') {
    $targets['md5pass'] = array(
      'name' => t('MD5\'ed password'),
      'description' => t('The already MD5\'ed user password.'),
      'callback' => 'first_benefit_feeds_password_support_set_target',
    );
    $targets['pass'] = array(
      'name' => t('Plain text password'),
      'description' => t('Plain text password that will get encrypted by Drupal.'),
    );
  }  
}

function MODULENAME_set_target( $source, &$entity, $target, $password_hash){
  // Saving password hash in the entity
  if (empty($password_hash)) {
    return;
  }
  $entity->feeds_imported_md5_hash = $password_hash;
}

function MODULENAME_user_insert(&$edit, $account, $category) {
  // Force the saved MD5 hash to the user after the user has been inserted and the UID is known
  
  if( isset( $account->feeds_imported_md5_hash ) ) {
    require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');

    // Lower than DRUPAL_HASH_COUNT to make the update run at a reasonable speed.
    $hash_count_log2 = 11;

    $rehashed_hash = user_hash_password( $account->feeds_imported_md5_hash, $hash_count_log2 );

    if ($rehashed_hash) {
      // Indicate an updated password.
      $update_hash  = 'U' . $rehashed_hash;
      db_update('users')
        ->fields(array('pass' => $update_hash))
        ->condition('uid', $account->uid)
        ->execute();
    }
  }
}

The tricky part was to actually get the MD5'ed password converted to the new Drupal 7 hash.
That part of the code is based on the user_update_7000 code available here: http://api.drupal.org/api/drupal/modules--user--user.install/function/us...

This is not a patch for the module and it is not tested outside of my own requirements.
Hope this can become a base for a solution.
If the maintainers of the module would like me to try writing a patch, I don't mind trying (not much experience)

mark trapp’s picture

Version: 7.x-2.0-alpha3 » 7.x-2.x-dev

Subscribe. #12 look good to me; I'm planning on putting it through its paces on 1,700 users tonight, but it should be RTBC.

kehan’s picture

I used #12 on an import of 14000 users without any hiccups. I'd say RTBC as well

mark trapp’s picture

Status: Needs review » Reviewed & tested by the community

Worked like a charm.

dave reid’s picture

Status: Reviewed & tested by the community » Needs review

This should probably add some kind of test to FeedsCSVtoUsersTest to ensure it works properly.

dave reid’s picture

StatusFileSize
new4.53 KB
dave reid’s picture

Version: 7.x-2.x-dev » 6.x-1.x-dev
Status: Needs review » Patch (to be ported)

#21 passes locally, so committing to Git: http://drupalcode.org/project/feeds.git/commit/b9dd6a0

dave reid’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev
Status: Patch (to be ported) » Fixed

Committed and manually tested on 6.x-1.x: http://drupalcode.org/project/feeds.git/commit/5e9dedc

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.