# Unicode usernames and group names

**URL:** https://meta.discourse.org/t/unicode-usernames-and-group-names/117737
**Category:** Announcements
**Tags:** new-feature
**Created:** [May 14, 2019, 8:18pm UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737 "2019-05-14T20:18:48Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [May 14, 2019, 8:18pm UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/1 "2019-05-14T20:18:48Z")

</div>

Lifting the restrictions on allowed characters in usernames is one of the oldest feature requests. Starting with Discourse 2.3.0.beta9 it’s finally possible to use Unicode characters within usernames and group names.

 ![image](https://global.discourse-cdn.com/meta/original/3X/5/0/506b1ba992c9b13344cd1416d0fa1197dbe4f4c3.png)

### New Site Settings

There are two new site settings: `allowed unicode username characters` and `unicode usernames`.

**`allowed unicode username characters`** allows you to allow only certain Unicode characters (e.g. `[äöüßÄÖÜẞ]` or `\p{Greek}`). By default Discourse permits letters ([Ll](https://www.compart.com/en/unicode/category/Ll) / [Lm](https://www.compart.com/en/unicode/category/Lm) / [Lo](https://www.compart.com/en/unicode/category/Lo) / [Lt](https://www.compart.com/en/unicode/category/Lt) / [Lu](https://www.compart.com/en/unicode/category/Lu)), marks ([Mc](https://www.compart.com/en/unicode/category/Mc), [Me](https://www.compart.com/en/unicode/category/Me), [Mn](https://www.compart.com/en/unicode/category/Mn)) and numbers ([Nd](https://www.compart.com/en/unicode/category/Nd), [Nl](https://www.compart.com/en/unicode/category/Nl), but _not_ [No](https://www.compart.com/en/unicode/category/No)). The setting can restrict those characters, but it’s not possible to allow additional characters. Also, it’s not possible to forbid ASCII letters and numbers.

You should tailor it to your community’s needs and only allow characters and scripts that are needed for the languages used by your community.

Take a look at the Ruby documentation if you want to know more about [character classes](https://ruby-doc.org/core/Regexp.html#class-Regexp-label-Character+Classes) and [character properties](https://ruby-doc.org/core/Regexp.html#class-Regexp-label-Character+Properties) in regular expressions.

**`unicode usernames`** is disabled by default and we **strongly advise** you to configure the `allowed unicode username characters` setting before enabling it in order to prevent [homograph username spoofing](https://www.google.com/search?q=homograph+attacks).

Example allowed values:

- zh\_CN Chinese: `[\p{Han}]`
- zh\_TW Chinese: `[\p{Han}]`
- ko Korean only: `[\p{Hangul}]`
- jp Japanese: `[\p{Han}\p{Katakana}\p{Hiragana}]`
- jp Japanese (カタカナ only): `[\p{Katakana}]`
- fi Finnish: `[åäöÅÄÖ]`
- cs Czech: `[ěščřžýáíéóůúďťň]`

### Letter Avatar Service

The Letter Avatar Service has been updated and we added support for generating avatars with the most commonly used scripts. Feel free to create a [pull request on GitHub](https://github.com/discourse/letter-avatars) to add a font from the [Google Noto Fonts](https://www.google.com/get/noto/) family if you encounter missing avatars for your language.

Enabling `unicode usernames` is only possible when the `external system avatars enabled` site setting is enabled, because the internal avatar generator doesn’t support Unicode. You can run your own instance of the [Letter Avatar Service](https://github.com/discourse/letter-avatars) if you can’t or don’t want to rely on the external service.

 ![image](https://global.discourse-cdn.com/meta/original/3X/2/f/2feda198ce2dcc1935f32de83226fb78175fcb90.png) We even support the brand new glyph for “令和” ([Reiwa](https://en.wikipedia.org/wiki/Reiwa)) that was added to Unicode in May.

### Good to know…

Discourse counts [_grapheme clusters_ (“user-perceived characters”)](http://www.unicode.org/reports/tr29/) instead of Unicode codepoints when it validates username length (`min username length` and `max username length` site settings). The Letter Avatar Service also uses the first grapheme cluster of a username to generate an avatar.

You should also take a look at the `reserved usernames` site setting. You might want to add additional usernames now that your forum supports Unicode in usernames.

### Feedback

Did you enable Unicode usernames for your community? We’d like to hear your feedback.  
Also, we want to ship sensible default values for the `unicode username character whitelist` for each locale supported by Discourse. Please feel free to suggest regular expressions in a reply.

---

<div class="post-metadata">

### Author: ![marguerite](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marguerite/32/120529_2.png) [@marguerite](https://meta.discourse.org/u/marguerite)
#### Post date: [May 15, 2019, 8:36am UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/2 "2019-05-15T08:36:09Z")

</div>

Thanks for the new feature!

I do have a discourse instance running for Chinese users, and I would like to test it.

But we have installed another plugin [discourse-username-localization](https://github.com/openSUSE-zh/discourse-username-localization) because previously unicode usernames were not supported officially.

So I would like to know how could I disable that plugin and switch to the official solution, will it break something? Any recommended steps to follow?

If this can be done, I think every CJK instance will switch to our official solution and contribute whitelist immediately 😀

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [May 15, 2019, 8:49am UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/3 "2019-05-15T08:49:35Z")

</div>

> [@marguerite](#):
>
> will it break something?

It looks like the plugin also changes the behavior for linking to CJK tags and categories. This will probably break, but we should fix it in Discourse core. That should be easy to fix.

Other than that disabling the plugin and enabling the official Unicode support should work without problems. Letter avatars will look differently afterwards, because the plugin currently converts Chinese usernames into latin characters. But I guess that’s a good thing. 🙂

---

<div class="post-metadata">

### Author: ![marguerite](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marguerite/32/120529_2.png) [@marguerite](https://meta.discourse.org/u/marguerite)
#### Post date: [May 15, 2019, 10:52am UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/4 "2019-05-15T10:52:48Z")

</div>

Thanks.

I ‘ll create a branch with those not implemented yet left and try the official solution so they may not conflict.

The tags and categories uses the same set of regex but in javascript which doesn’t support \p{Katakana} stuff. I raised an issue to unify regex in that plugin, but the attempt failed. is it possible to use the same whitelist in the official implementation? eg a converter to convert ruby whitelist to javascript.

And the unicode avatar is just excellent!

---

<div class="post-metadata">

### Author: ![marguerite](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marguerite/32/120529_2.png) [@marguerite](https://meta.discourse.org/u/marguerite)
#### Post date: [May 15, 2019, 1:47pm UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/5 "2019-05-15T13:47:21Z")

</div>

I just switched my [forum](https://forum.suse.org.cn) to unicode username.

I updated discourse-username-localization to remove all the ruby stuff. (can’t wait to see you guys fix hashtags and mentions in the core, so I can abandon it completely)

And use this whitelist:

```
[\p{Han}\p{Katakana}\p{Hiragana}\p{Hangul}]

```

And update letter\_avatar service to v4.

Now it works

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [May 15, 2019, 1:53pm UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/6 "2019-05-15T13:53:04Z")

</div>

> [@marguerite](#):
>
> mentions

I think mentions are already supported 🤔

---

<div class="post-metadata">

### Author: ![rizka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rizka/32/79717_2.png) [@rizka](https://meta.discourse.org/u/rizka)
#### Post date: [May 15, 2019, 3:00pm UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/7 "2019-05-15T15:00:26Z")

</div>

> [@gerhard](#):
>
> Also, we want to ship sensible default values for the `unicode username character whitelist` for each locale supported by Discourse. Please feel free to suggest regular expressions in a reply.

For Finnish, it should be [åäöÅÄÖ].

---

<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: [May 15, 2019, 3:42pm UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/8 "2019-05-15T15:42:07Z")

</div>

> [@rizka](#):
>
> åäöÅÄÖ

Isn’t this your real Finnish name @rizka 😉

---

<div class="post-metadata">

### Author: ![rizka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rizka/32/79717_2.png) [@rizka](https://meta.discourse.org/u/rizka)
#### Post date: [May 15, 2019, 3:57pm UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/9 "2019-05-15T15:57:42Z")

</div>

Not quite, I have just one of those in my surname. 🙂

Å/å is actually not a pure Finnish language letter. It never appears anywhere except the Finnish alphabet, computer keyboards and names of Swedish people and places. Ö/ö is somewhat rare. Ä/ä is by far the most common, but for a reason unknown to me, very uncommon in Finnish first names. Appears in many surnames, though, like mine. 🙂

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [May 15, 2019, 3:57pm UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/10 "2019-05-15T15:57:52Z")

</div>

@marguerite You should also remove `mentions.js.es6` from the plugin. There’s no need to patch anything related to usernames anymore. Only your customizations for categories and tags might still be needed, but we will fix that as well.

> [@marguerite](#):
>
> And use this whitelist:
> 
> ```plaintext
> [\p{Han}\p{Katakana}\p{Hiragana}\p{Hangul}]+?
> 
> ```

The `+?` at the end of the regex isn’t needed.  
Out of curiosity: Can this whitelist be used for both `zh_CN` and `zh_TW` or is there a difference?

---

<div class="post-metadata">

### Author: ![marguerite](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marguerite/32/120529_2.png) [@marguerite](https://meta.discourse.org/u/marguerite)
#### Post date: [May 16, 2019, 3:18am UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/11 "2019-05-16T03:18:52Z")

</div>

@gerhard

I removed mentions.js.es6, do I need to remove override-username-match.js.es6 as well?

\p{Han} covers traditional and simplified Chinese. My whitelist will allow CJK usernames

---

<div class="post-metadata">

### Author: ![danekhollas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danekhollas/32/79637_2.png) [@danekhollas](https://meta.discourse.org/u/danekhollas)
#### Post date: [May 16, 2019, 8:41am UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/12 "2019-05-16T08:41:29Z")

</div>

> [@gerhard](#):
>
> Please feel free to suggest regular expressions in a reply.

For EU langs it might be easiest to just allow all [extended latin](https://en.wikipedia.org/wiki/Latin_Extended-A) if possible, rather than hand-picking specific letters for every language. 🙂

EDIT: Although reading a bit more about homograph attack, might not be the best idea after all. 😊  
Here are chars for Czech;

`ěščřžýáíéóůúďťň`

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [May 17, 2019, 12:28am UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/13 "2019-05-17T00:28:40Z")

</div>

> [@marguerite](#):
>
> do I need to remove override-username-match.js.es6 as well?

Yes, you can remove that as well. Looks like that part of the plugin is broken anyway. User cards were refactored about a year ago.

---

<div class="post-metadata">

### Author: ![fantasticfears](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fantasticfears/32/119608_2.png) [@fantasticfears](https://meta.discourse.org/u/fantasticfears)
#### Post date: [May 17, 2019, 7:21am UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/14 "2019-05-17T07:21:51Z")

</div>

Katakana and Hiragana are both Japanese. Hangul is Korean.

I love this work. And I think a default setting below should work:

- zh\_CN, zh\_TW: `\p{Han}`. This covers Chinese characters. Some communities can use more other characters. Maybe not default.
- ko: `\p{Hangul}`. Korean don’t write Chinese at all. (I heard there are some Chinese characters in use in Korean?)
- jp: `[\p{Han}\p{Katakana}\p{Hiragana}]` Japanese use all of them.

And maybe it’s good to mention `reserved_usernames` 😅Unicode username does enable more names to be fake as admin/moderator.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [May 17, 2019, 10:14am UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/15 "2019-05-17T10:14:46Z")

</div>

Thanks for the regular expressions and also for the tip regarding `reserved usernames`. I added a note in the first post.

---

<div class="post-metadata">

### Author: ![pgr](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pgr/32/156783_2.png) [@pgr](https://meta.discourse.org/u/pgr)
#### Post date: [September 20, 2019, 12:46pm UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/16 "2019-09-20T12:46:49Z")

</div>

How does this option affect migrations? I am migrating from Kunena with a script based on the “official” `kunena3.rb` script.

I have a user called `abd-def` (for example). It gets imported as `abcdef`.

Then I turned on this option for the unicode usernames and deleted that user, and re-ran the script. It was again imported as `abddef` ☹

How can I ensure my user names with dashes don’t get changed during import?

Thanks!

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [September 20, 2019, 1:00pm UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/17 "2019-09-20T13:00:52Z")

</div>

The removal of the dash has nothing to do with Unicode usernames. That’s happening because the import script manipulates the username during the import.

> <https://github.com/discourse/discourse/blob/7f8cdea9244760b7f27bcebb86de0121006f0ce3/script/import_scripts/kunena3.rb#L89-L93>

I don’t think there’s any need for that. Try replacing those lines with the following code snippet. It should work.

```ruby
@users[u['id'].to_i] = { id: u['id'].to_i, username: u['username'], email: u['email'], created_at: u['registerDate'] }

```

---

<div class="post-metadata">

### Author: ![mentalstring](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mentalstring/32/168934_2.png) [@mentalstring](https://meta.discourse.org/u/mentalstring)
#### Post date: [January 29, 2020, 2:08pm UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/18 "2020-01-29T14:08:08Z")

</div>

I’m happy to see support for Unicode usernames and group names 👍.

With the introduction of the support for Unicode usernames however, there’s now a bit of a odd situation where Discourse can support something like `中国` or `ไทย` as a username, but not `-dashing-` as it [still requires](https://github.com/discourse/discourse/blob/master/app/models/username_validator.rb) the first and last character to be a letter, number or underscore (but not a dash).

I tried using the Unicode support setting to add support for the dash character but that didn’t seem to work for me, although I may have missed something.

Would it make sense to revise this rule for the first/last characters about the dash now that Unicode is supported? Is there a reason to continue not allowing dash on the first&last position but allow any non-ASCII letter (including the underscore)? Dash doesn’t seem to require special encoding on URLs, but maybe there’s another reason for this?

I know this is a bit of a tangent to the topic, so let me know if I should open a separate one.

---

<div class="post-metadata">

### Author: ![sok777](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@sok777](https://meta.discourse.org/u/sok777)
#### Post date: [January 4, 2022, 2:02pm UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/19 "2022-01-04T14:02:46Z")

</div>

@gerhard Can a user name be like this?

`discource__ `  
or  
`discource_name`  
?

Because I can’t seem to make it work!

TIA

---

<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: [January 4, 2022, 2:05pm UTC](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737/20 "2022-01-04T14:05:27Z")

</div>

See `reserved_usernames` site setting.

[Next page](https://meta.discourse.org/t/unicode-usernames-and-group-names/117737.md?page=2)
