# How does "Require Username" work for custom database connections?

**URL:** <https://community.auth0.com/t/how-does-require-username-work-for-custom-database-connections/50660>\
**Category:** Get Help\
**Tags:** username, custom-database, login\
**Created:** [September 29, 2020, 4:06pm UTC](https://community.auth0.com/t/how-does-require-username-work-for-custom-database-connections/50660 "2020-09-29T16:06:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![john6](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john6/32/24298_2.png) [@john6](https://community.auth0.com/u/john6)\
**Post date:** [September 29, 2020, 4:06pm UTC](https://community.auth0.com/t/how-does-require-username-work-for-custom-database-connections/50660/1 "2020-09-29T16:06:58Z")

</div>

A clear explanation of how authentication works when using a custom database connection would be helpful.

For example, on the Database Connections page, on the Custom Database tab, one is able to write custom code to create authentication functionality with an external database.

The login template has parameters for email and password but nothing for username. It’s unclear to me how this is meant to be implemented when a user has the option to login with a username instead of an email.

Similarly, it’s not clear how this information would be stored based on the Create a new user function template.

---

<div class="post-metadata">

**Author:** ![joseantonio.rey](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/joseantonio.rey/32/14670_2.png) [@joseantonio.rey](https://community.auth0.com/u/joseantonio.rey)\
**Post date:** [September 29, 2020, 5:25pm UTC](https://community.auth0.com/t/how-does-require-username-work-for-custom-database-connections/50660/2 "2020-09-29T17:25:46Z")

</div>

Hello, @john6,

For Custom Databases, you actually build your own script to retrieve whatever user information you need from the legacy datasource. Once you do that, you build, within the same script, a user profile according to Auth0’s specification.

In this case, instead of attempting to retrieve the email from the legacy datasource, you should attempt to retrieve the username, which you can then put into the Auth0 profile.

The profile would be they copied over to Auth0. If you have Import Mode on, it would also copy the password over, and next time the user authenticates, it would do it against Auth0 and the profile you created in the first login attempt, rather than contacting the legacy datasource.

Let me know if this helps.

---

<div class="post-metadata">

**Author:** ![john6](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john6/32/24298_2.png) [@john6](https://community.auth0.com/u/john6)\
**Post date:** [September 29, 2020, 5:59pm UTC](https://community.auth0.com/t/how-does-require-username-work-for-custom-database-connections/50660/3 "2020-09-29T17:59:30Z")

</div>

Thanks for the response.

I’ve written my own script already for the Login, Create, and Change Password targets within Auth0.

However it’s unclear to me from the login UI how the email/username would be processed.

See this screenshot for example: here is the way a user would login. There is a single field for “username/email”.

 ![Capture](https://global.discourse-cdn.com/auth0/original/3X/a/b/ab85f0170481986fddfb0a91c5c4d9473cc7fe52.png)

Another example is the Sign Up tab of the same prompt. This prompt has two separate inputs for username and for email.

 ![Capture](https://global.discourse-cdn.com/auth0/original/3X/3/0/30890c2d556593407d56a9d8ad9ba1d04e7f8948.png)

In the back-end Login script, the template begins with `function login(email, password, callback) { `. There is a spot for email but not for username. Will Auth0’s form send the input for “username/email” to the email parameter?

Similarly in the Create script, the template begins with `function create(user, callback) {`. Will the user object here contain both the username and email values from the Sign Up form?

---

<div class="post-metadata">

**Author:** ![joseantonio.rey](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/joseantonio.rey/32/14670_2.png) [@joseantonio.rey](https://community.auth0.com/u/joseantonio.rey)\
**Post date:** [September 29, 2020, 10:01pm UTC](https://community.auth0.com/t/how-does-require-username-work-for-custom-database-connections/50660/4 "2020-09-29T22:01:01Z")

</div>

Hi @john6,

You are spot-on for both of them 🙂 I was going to draft something more extensive but I think you’ve described it quite well.

---

<div class="post-metadata">

**Author:** ![john6](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john6/32/24298_2.png) [@john6](https://community.auth0.com/u/john6)\
**Post date:** [September 30, 2020, 2:41pm UTC](https://community.auth0.com/t/how-does-require-username-work-for-custom-database-connections/50660/5 "2020-09-30T14:41:41Z")

</div>

😂 well, glad to know my intuition was correct then.

I’ll try an implementation and comment here if I get into any issues.

---

<div class="post-metadata">

**Author:** ![john6](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john6/32/24298_2.png) [@john6](https://community.auth0.com/u/john6)\
**Post date:** [September 30, 2020, 4:10pm UTC](https://community.auth0.com/t/how-does-require-username-work-for-custom-database-connections/50660/6 "2020-09-30T16:10:42Z")

</div>

Hmmm I’m still having issues with getting this to work. I made a separate topic because there also seems to be an issue with the Test prompt for the Create function.

> [@Discrepency between Sign Up prompt and Create prompt in custom-database](https://community.auth0.com/t/discrepency-between-sign-up-prompt-and-create-prompt-in-custom-database/50726):
>
> In our app we’ve enabled the Require Username feature and we are using a custom database connection This is demonstrated in our Sign Up prompt on our site, pictured below. [singup] However when I am customizing the functionality for the Create target within the Auth0 dev environment, the prompt is different. [TRY prompt] In this case there is only a single field “Username/Email”. The logic here seems off – the Sign Up form effectively requires Username AND Email whereas the Test prompt req…
