# phpBB importer fails to import anonymous users differing only by letter case

**URL:** <https://meta.discourse.org/t/phpbb-importer-fails-to-import-anonymous-users-differing-only-by-letter-case/47083>\
**Category:** Bug\
**Created:** [July 11, 2016, 11:01am UTC](https://meta.discourse.org/t/phpbb-importer-fails-to-import-anonymous-users-differing-only-by-letter-case/47083 "2016-07-11T11:01:14Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![palant](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/palant/32/104531_2.png) [@palant](https://meta.discourse.org/u/palant)\
**Post date:** [July 11, 2016, 11:01am UTC](https://meta.discourse.org/t/phpbb-importer-fails-to-import-anonymous-users-differing-only-by-letter-case/47083/1 "2016-07-11T11:01:14Z")

</div>

When importing anonymous users from phpBB I get the following error:

> Error on record: {:email=\>“anonymous\_no\_email\_Надежда”, :username=\>“111104”, :name=\>“”, :created\_at=\>Mon, 10 Nov 2014 15:09:15 UTC +00:00, :active=\>true, :trust\_level=\>0, :approved=\>true, :approved\_by\_id=\>-1, :approved\_at=\>2016-07-11 10:40:21 +0000, :import\_mode=\>true, :last\_emailed\_at=\>2016-07-11 10:40:21 +0000}  
> /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/rack-mini-profiler-0.10.1/lib/patches/db/pg.rb:90:in `exec’: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint “index\_users\_on\_email” (ActiveRecord::RecordNotUnique)  
> DETAIL: Key (lower(email::text))=(anonymous\_no\_email\_надежда) already exists.  
> : INSERT INTO “users” (“email”, “username”, “name”, “created\_at”, “active”, “trust\_level”, “approved”, “approved\_by\_id”, “approved\_at”, “last\_emailed\_at”, “username\_lower”, “updated\_at”) VALUES (‘anonymous\_no\_email\_Надежда’, ‘111104’, ‘’, ‘2014-11-10 15:09:15.000000’, ‘t’, 0, ‘t’, -1, ‘2016-07-11 10:40:21.494781’, ‘2016-07-11 10:40:21.599263’, ‘111104’, ‘2016-07-11 10:40:21.622126’) RETURNING “id”

It seems that we have guest posts under the names “НАДЕЖДА” and “Надежда” - it’s the same name, the first one merely being all-caps. As the importer doesn’t treat anonymous user names as case-insensitive, it tries to create two accounts here (probably not wrong). Trouble is, the generated email address violates uniqueness requirements which treat email addresses as case-insensitive. Looking at the source code, this issue doesn’t seem to be limited to Cyrillic, it would be just the same with Latin.

I’m running the import script from Discourse 1.5.3, master seems to have the same issue however. Given that treating account names as case-sensitive is desired, maybe the simplest solution is adding a hash of the username to the generated “email address”? This patch seems to solve the issue:

```
diff --git a/script/import_scripts/phpbb3/importers/user_importer.rb b/script/import_scripts/phpbb3/importers/user_importer.rb
index ca50197..3f91a52 100644
--- a/script/import_scripts/phpbb3/importers/user_importer.rb
+++ b/script/import_scripts/phpbb3/importers/user_importer.rb
@@ -47,11 +47,13 @@ module ImportScripts::PhpBB3
     end
 
     def map_anonymous_user(row)
+ require 'digest/md5'
       username = row[:post_username]
+ md5 = Digest::MD5.hexdigest(username)
 
       {
         id: username,
- email: "anonymous_no_email_#{username}",
+ email: "anonymous_no_email_#{username}_#{md5}",
         username: username,
         name: '',
         created_at: Time.zone.at(row[:first_post_time]),

```

---

_[View the full topic](https://meta.discourse.org/t/phpbb-importer-fails-to-import-anonymous-users-differing-only-by-letter-case/47083)._
