# Importer support for migrated passwords

**URL:** https://meta.discourse.org/t/importer-support-for-migrated-passwords/70543
**Category:** Development
**Created:** [9월 21, 2017, 11:05오후 UTC](https://meta.discourse.org/t/importer-support-for-migrated-passwords/70543 "2017-09-21T23:05:02Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [9월 21, 2017, 11:05오후 UTC](https://meta.discourse.org/t/importer-support-for-migrated-passwords/70543/1 "2017-09-21T23:05:02Z")

</div>

I mostly think that importing passwords from a legacy forum is a Bad Idea. There are almost certainly a bunch of horrible passwords and it seems like making people change their password when they get a shiny new forum is a fine idea, but it seems that people want to do that anyway.

There’s a plugin that offers [Migrated password hashes support](https://meta.discourse.org/t/migrated-password-hashes-support/19512). I just put that code into the `vbulletin` importer for some folks. Should I leave it in or take it out before I submit the PR with other useful stuff in it?

Since the passwords are completely ignored unless the plugin is installed, it doesn’t hurt much to just include the passwords, but I’d probably add a switch so that they’d not be included by default.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [9월 22, 2017, 6:51오전 UTC](https://meta.discourse.org/t/importer-support-for-migrated-passwords/70543/2 "2017-09-22T06:51:01Z")

</div>

Maybe include it but default it to off? Explain the downsides in the place where you would enable it?

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [9월 24, 2017, 7:03오전 UTC](https://meta.discourse.org/t/importer-support-for-migrated-passwords/70543/3 "2017-09-24T07:03:34Z")

</div>

I think it’s fine to always import previous password hashes & salts. It’s just text, so that won’t take too much space. That way, people who want to allow their users to use their previous password can just add the linked plugin and be done.

---

<div class="post-metadata">

### Author: ![pmule](https://avatars.discourse-cdn.com/v4/letter/p/7c8e57/32.png) [@pmule](https://meta.discourse.org/u/pmule)
#### Post date: [3월 12, 2018, 4:32오후 UTC](https://meta.discourse.org/t/importer-support-for-migrated-passwords/70543/4 "2018-03-12T16:32:55Z")

</div>

Hi all. I am trying to migrate a forum from discuz x to discourse (v2.0.0.beta4), but running the corresponding import script results

> creating users  
> 1 / 242 ( 0.4%) /home/localadmin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activemodel-5.1.4/lib/active\_model/attribute\_assignment.rb:48:in `_assign_attribute': unknown attribute 'import_pass' for User. (ActiveModel::UnknownAttributeError) from /home/localadmin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activemodel-5.1.4/lib/active_model/attribute_assignment.rb:40:in `block in \_assign\_attributes’  
> from /home/localadmin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activemodel-5.1.4/lib/active\_model/attribute\_assignment.rb:39:in `each' from /home/localadmin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activemodel-5.1.4/lib/active_model/attribute_assignment.rb:39:in `\_assign\_attributes’  
> from /home/localadmin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activerecord-5.1.4/lib/active\_record/attribute\_assignment.rb:26:in `_assign_attributes' from /home/localadmin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activemodel-5.1.4/lib/active_model/attribute_assignment.rb:33:in `assign\_attributes’  
> from /home/localadmin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activerecord-5.1.4/lib/active\_record/core.rb:337:in `initialize' from /home/localadmin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activerecord-5.1.4/lib/active_record/inheritance.rb:66:in `new’  
> from /home/localadmin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activerecord-5.1.4/lib/active\_record/inheritance.rb:66:in `new' from /home/localadmin/git/discourse/script/import_scripts/base.rb:313:in `create\_user’  
> from /home/localadmin/git/discourse/script/import\_scripts/base.rb:242:in `block in create_users' from /home/localadmin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rack-mini-profiler-0.10.7/lib/patches/db/mysql2.rb:6:in `each’  
> from /home/localadmin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rack-mini-profiler-0.10.7/lib/patches/db/mysql2.rb:6:in `each' from /home/localadmin/git/discourse/script/import_scripts/base.rb:230:in `create\_users’  
> from script/import\_scripts/discuz\_x.rb:163:in `block in import_users' from /home/localadmin/git/discourse/script/import_scripts/base.rb:824:in `block in batches’  
> from /home/localadmin/git/discourse/script/import\_scripts/base.rb:823:in `loop' from /home/localadmin/git/discourse/script/import_scripts/base.rb:823:in `batches’  
> from script/import\_scripts/discuz\_x.rb:137:in `import_users' from script/import_scripts/discuz_x.rb:56:in `execute’  
> from /home/localadmin/git/discourse/script/import\_scripts/base.rb:46:in `perform' from script/import_scripts/discuz_x.rb:1064:in `’

It seems that the custom field “import\_pass” are failed to handle somewhere.  
Does this happen because some plugins are absent with my environment?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [3월 12, 2018, 4:35오후 UTC](https://meta.discourse.org/t/importer-support-for-migrated-passwords/70543/5 "2018-03-12T16:35:52Z")

</div>

Change it to `password` instead of `import_pass`. Or, if you’re not going to use the `migrate-passwords` plugin, just comment out or delete that line.

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [3월 12, 2018, 5:13오후 UTC](https://meta.discourse.org/t/importer-support-for-migrated-passwords/70543/6 "2018-03-12T17:13:06Z")

</div>

Changing it to `password` will probably not do the trick, because there is a separate salt field a few lines below. It should probably be something like

`password: user['password_hash']+':'+user['salt']`

and then delete the lines

`import_pass: user['password_hash'],`

and

`salt: user['salt'],`

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [3월 12, 2018, 5:15오후 UTC](https://meta.discourse.org/t/importer-support-for-migrated-passwords/70543/7 "2018-03-12T17:15:01Z")

</div>

> [@RGJ](#):
>
> because there is a separate salt field a few lines below.

Oops! Thanks, Richard. @pmule, if you want imported passwords to work, you should pay attention to this!

---

<div class="post-metadata">

### Author: ![pmule](https://avatars.discourse-cdn.com/v4/letter/p/7c8e57/32.png) [@pmule](https://meta.discourse.org/u/pmule)
#### Post date: [3월 12, 2018, 5:22오후 UTC](https://meta.discourse.org/t/importer-support-for-migrated-passwords/70543/8 "2018-03-12T17:22:49Z")

</div>

Thanks. Now the import\_users passed, but now it failed on import\_categories when executing

```
raw = process_discuzx_post(row['rules'], nil)
          if @bbcode_to_md
            raw = raw.bbcode_to_md(false) rescue raw
          end
          category.topic.posts.first.update_attribute(:raw, raw)

```

with error

```
creating categories
       14 / 52 ( 26.9%) script/import_scripts/discuz_x.rb:288:in `block (2 levels) in import_categories': undefined method `update_attribute' for nil:NilClass (NoMethodError)
	from /home/localadmin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activesupport-5.1.4/lib/active_support/core_ext/object/try.rb:17:in `public_send'
	from /home/localadmin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activesupport-5.1.4/lib/active_support/core_ext/object/try.rb:17:in `try!'
	from /home/localadmin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activesupport-5.1.4/lib/active_support/core_ext/object/try.rb:6:in `try'
	from /home/localadmin/git/discourse/script/import_scripts/base.rb:451:in `create_category'
	from /home/localadmin/git/discourse/script/import_scripts/base.rb:417:in `block in create_categories'
	from /home/localadmin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rack-mini-profiler-0.10.7/lib/patches/db/mysql2.rb:6:in `each'
	from /home/localadmin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rack-mini-profiler-0.10.7/lib/patches/db/mysql2.rb:6:in `each'
	from /home/localadmin/git/discourse/script/import_scripts/base.rb:398:in `create_categories'
	from script/import_scripts/discuz_x.rb:263:in `import_categories'
	from script/import_scripts/discuz_x.rb:57:in `execute'
	from /home/localadmin/git/discourse/script/import_scripts/base.rb:46:in `perform'
	from script/import_scripts/discuz_x.rb:1065:in `<main>'

```

Does the last call legal?
