# Recreating the single sign on logic for generating usernames

**URL:** https://meta.discourse.org/t/recreating-the-single-sign-on-logic-for-generating-usernames/67748
**Category:** Development
**Created:** [August 10, 2017, 12:11am UTC](https://meta.discourse.org/t/recreating-the-single-sign-on-logic-for-generating-usernames/67748 "2017-08-10T00:11:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![SwisherSweet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/swishersweet/32/119523_2.png) [@SwisherSweet](https://meta.discourse.org/u/SwisherSweet)
#### Post date: [August 10, 2017, 12:11am UTC](https://meta.discourse.org/t/recreating-the-single-sign-on-logic-for-generating-usernames/67748/1 "2017-08-10T00:11:46Z")

</div>

Howdy,

I’m pre-populating users in Discourse from an integrated SSO external system and would like to mimic the username creation process in Discourse.

Currently, I’m having to create usernames like so, where the number is the unique user id.

u12345678  
u23456789

I tried using portions of name or email but always ended up with complaints about special characters.

When a user logs into the site using SSO, the username is automagically created. The username is a reasonable representation of the user and I’d like to copy this functionality with my pre-populated users.

Does anyone know what the logic is and/or can point me to the code in GIT that performs the magic?

Thank you.

---

<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: [August 10, 2017, 12:18am UTC](https://meta.discourse.org/t/recreating-the-single-sign-on-logic-for-generating-usernames/67748/2 "2017-08-10T00:18:50Z")

</div>

> [@SwisherSweet](#):
>
> Does anyone know what the logic is and/or can point me to the code in GIT that performs the magic?

Here you go:

> <https://github.com/discourse/discourse/blob/bb0fa5abbc6da2ad32ec52264796ee78d1cf3a45/lib/user_name_suggester.rb>

---

<div class="post-metadata">

### Author: ![jerdog](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jerdog/32/122843_2.png) [@jerdog](https://meta.discourse.org/u/jerdog)
#### Post date: [January 5, 2018, 1:36pm UTC](https://meta.discourse.org/t/recreating-the-single-sign-on-logic-for-generating-usernames/67748/3 "2018-01-05T13:36:37Z")

</div>

So if I understand this correctly, Discourse automagically does this when you have SSO setup/integrated?

---

<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: [January 5, 2018, 4:52pm UTC](https://meta.discourse.org/t/recreating-the-single-sign-on-logic-for-generating-usernames/67748/4 "2018-01-05T16:52:34Z")

</div>

Only if you don’t supply a valid username.

---

<div class="post-metadata">

### Author: ![jerdog](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jerdog/32/122843_2.png) [@jerdog](https://meta.discourse.org/u/jerdog)
#### Post date: [January 5, 2018, 5:05pm UTC](https://meta.discourse.org/t/recreating-the-single-sign-on-logic-for-generating-usernames/67748/5 "2018-01-05T17:05:26Z")

</div>

Ok - so if we use SSO (Auth0) and when it goes to create a username, if there’s one already existing in Discourse with that name then it will create a different one, like a variation?
